最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get input value to modal box jquery UI - Stack Overflow

programmeradmin4浏览0评论
<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>
<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>
Share Improve this question asked Mar 18, 2013 at 9:10 EmanuelEmanuel 1652 gold badges2 silver badges4 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4

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

 }
});

Emanuel, start by reading some useful info:

http://www.w3schools./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()

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())
    }
    });

You can use:

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

For Bootstrap Modal:

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

评论列表(0)

  1. 暂无评论