Emanuel
Emanuel

Reputation: 165

How to get input value to modal box jquery UI

<div id="befor-box">
   <form id="newsletter-form" name="newsletter-form" action="/sub/" method="post">{% csrf_token %}
      <input name="email" type="text" value="Enter your Email here" class="text"/> 
      <input class="submit" onclick="showDialog();" value="Subscribe!" />
   </form>
</div>

How to get EMAIL value from:

<input name="email" type="text" value="Enter your Email here" class="text"/>

to:

<input name="email" type="text" value="" class="text"/>

from here:

<div id="dialog-modal" style="display:none;">
   <form name="newsletter-form" action="/sub/" method="post">
      <input name="email" type="text" value="" class="text"/>
      <input name="fname" type="text" value="First name" class="text"/>
      <input name="lname" type="text" value="Last name" class="text"/>
      <input type="submit" class="submit" value="Subscribe!" />
   </form>
</div>
<script type="text/javascript">
   function showDialog()
   {
   $( "#dialog-modal" ).dialog({


   });
   }
</script>

Upvotes: 5

Views: 28042

Answers (4)

Faridul Khan
Faridul Khan

Reputation: 2007

You can use:

$("input[name=email]");

For Bootstrap Modal:

$('.modal-body input[name=email]').val(email);

Upvotes: 0

Iker V&#225;zquez
Iker V&#225;zquez

Reputation: 567

Add an id on both inputs:

<input name="email" type="text" value="Enter your Email here" class="text" id="email_orig"/>

<input name="email" type="text" value="" class="text" id="email_dst"/>

Then override the open event:

    function showDialog()
    {
    $( "#dialog-modal" ).dialog({
         open: function(){
         $("#email_dst").val($("#email_orig").val())
    }
    });

Upvotes: 1

bipen
bipen

Reputation: 36531

use open event of dialog which is called whn dialog opens... so replace the value there..

$( "#dialog-modal" ).dialog({
 open: function( event, ui ) {
     var boxInput=$("#befor-box").find('input[name="email"]').val(); //get the value..
     $("#dialog-modal").find('input[name="email"]').val(boxInput); //set the valu

 }
});

Upvotes: 4

Wiseman
Wiseman

Reputation: 1069

Emanuel, start by reading some useful info:

http://www.w3schools.com/jquery/jquery_selectors.asp "The #id Selector" chapter especially.

After that, you can add 'id' attributes to your DOM structure and retrieve input value as simple as

$('#my-input-id').val()

Upvotes: 2

Related Questions