I have couple of forms with different ids but with same input names and ids. For example:
<form id="form1>
<input name="email" id="email" value="test@test.com"/>
.....
</form>
<form id="form2>
<input name="email" id="email" value="test@test.com"/>
.....
</form>
And in my Jquery ready function I have below code. This works fine in FireFox, Chrome but not in IE7. That is alert function showing email value as “test@test.com” in FireFox, Chrome but IE7 showing as “undefined”. Any suggestions?
$(document).ready(function() {
alert($("#form1 #emailAddress").val());
});
Duplicate IDs are invalid, and I wouldn’t count on any selector filtering to work in the current, past, or future versions of jQuery. Those elements shouldn’t have ids, and they should be selected by name.
e.g:
$('#form1 [name=email]')$('#form2 [name=email]')