Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
15
rated 0 times [  17] [ 2]  / answers: 1 / hits: 25033  / 8 Years ago, wed, july 27, 2016, 12:00:00

The relevant part of the code is shown below. When I click the Submit button, on the alert box, I get undefined, rather than the typed email. What mistake am I doing here?



<form action=page2.php method=post onsubmit=myFunction() id=form1> 
......
<input type=text name=YourEMail style=width: 250px;>
<input type=submit name=submit value=Submit> <br>
......
</form>

<script>
$('#form1').submit(function() {
//your validation rules here
var email = $('#YourEMail').val()
alert(email)
//if(email.length == 0)
return false;
//else
// return true;
});
</script>

More From » php

 Answers
6

YourEMail is the name, not the id:



var email = $('input[name=YourEMail]').val();


Or change the input to have the id:



<input type=text id=YourEMail name=YourEMail style=width: 250px;> 

[#61238] Sunday, July 24, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
michelecarissab

Total Points: 730
Total Questions: 97
Total Answers: 110

Location: Uzbekistan
Member since Sat, Feb 27, 2021
3 Years ago
;