Calling Javascript inside Modal

Asked

Viewed 781 times

1

It is possible to get a result of a Javascript function and play this result inside a Modal?

I have this function:

<script>

$('#download').click(function() {
    document.getElementById('xxxx').disabled=false
    document.getElementById('xxxx').disabled=false

    var formData = $(document.forms[0]).serialize().split('&').join('\n');


    this.href = 'data: ,' +  formData ;




    document.getElementById('xxxx').disabled=true
    document.getElementById('xxxxx').disabled=true

});

</script>   

The result "formData" would have to be played inside a modal Popup. Its code:

<div class="bs-example">
    <!-- Button HTML (to Trigger Modal) -->
    <a href="#myModal" class="btn btn-lg btn-primary" data-toggle="modal" >Clique aqui para ver a janela</a>
   <!-- Modal HTML -->
    <div id="myModal" class="modal fade">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title">Atenção!</h4>
                </div>
                <div class="modal-body">

                    </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
                    <button type="button" class="btn btn-primary">Salvar tudo</button>
                </div>
            </div>
        </div>
    </div>
</div> 
  • Dear; I ask you to disregard the above question, it was "stung".

  • What do you mean by perforated? No one changed anything in the question, only there was a code formatting and title improvement. If it is perforated also you can edit it and add more information.

  • I thought she n had gone formatted and it would get messy. It was my first interaction to this forum. Grateful.

  • this is not a forum, it is a Q&A, just to make the difference clear. You can edit the question as many times as you want and if you don’t have answers, you can delete it too.

  • Grateful for the response.

2 answers

0


Expensive;

I solved my problem with the code below:

function copy_form()
    {
id('modalxxx').value = id('xxx').value;
id('modalyyy').value = id('yyy').value;
id('modalrrr').value = id('rrr').value;
id('modalttt').value = id('ttt').value;


    }

 function id( el ){
  return document.getElementById( el );
                  }
    window.onload = function()
       {
    id('btnenviar').onclick = function()
       }
    copy_form();
      }
   }

</script> 

Thanks for your help :)

0

Can give an ID to the div who will receive the content

<div class="modal-body" id="conteudoModal">

And then after the form date

var formData = $(document.forms[0]).serialize().split('&').join('\n');
document.getElementById('conteudoModal').innerHTML(formData);

Would that be?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.