javascript - Unable to get email address onclick function -
this question has answer here:
- get value of input in jquery 5 answers
<div id="divform" class="fancybox" style="display:none;"> <form id="frm_step1" action="download1.php" method="post"> <label>enter email</label> <input type="email" name="email" id="email" value="" required /> <input type="button" name="submit" id="submit" value="submit" class="form-submit" target-form="frm_step1" onclick="test();" /> </form> </div>
function test() { var email = $('#email').text(); alert(email); $.ajax({ type: "post", datatype: "json", url: 'download1.php?email' + email, data: { 'email': email }, success: function(data) { window.location.href = 'download.php#file'; }, error: function(e) { alert('error: ' + e); } }); }
i not able email this. when put alert returns blank. , use jquery/ajax time not alert email address.
use .val()
instead of .text()
. .val()
method used values of form elements such input, select , textarea.
$('#email').val();
function test() { var email = $('#email').val(); alert(email); $.ajax({ type: "post", datatype: "json", url: 'download1.php?email' + email, data: { 'email': email }, success: function(data) { window.location.href = 'download.php#file'; }, error: function(e) { alert('error: ' + e); } }); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="divform" class="fancybox"> <form id="frm_step1" action="download1.php" method="post"> <label>enter email</label> <input type="email" name="email" id="email" value="" required /> <input type="button" name="submit" id="submit" value="submit" class="form-submit" target-form="frm_step1" onclick="test();" /> </form> </div>
Comments
Post a Comment