I writing a simple page to check if someone is entering the correct email twice. I want to display in another element on the page weather or not the email in the second form block is the same as the first. I’m using the jquery id selector.
<head>
<script type="text/javascript" src="jquery1.8.3-min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
function emailCheck(){
if($("#email").val() != $("#email2").val())
{
$("#err").innerText = "emails don't match, sucka";
$("#test").textContent = "emails don't match, sucka";
$("#test2").innerHtml = "emails don't match, sucka";
document.getElementById("getEleTest").innerText = "emails don't match, sucka";
alert("dont match");
}
}
</script>
</head>
<body>
<form action="SignUp" method="POST">
<table>
<label for="email">Email</label></br>
<input id="email" type ="email" name="email1111"/> </br>
<label for="email2" > Enter Email Again </label></br>
<input id="email2" type="email" name="email21111" onkeyup="emailCheck();"></br>
<input type="submit" value="Sign Up">
</table>
</form>
<div id="err"></div>
<div id="test"></div>
<div id="test2"></div>
<div id="getEleTest"></div>
</body>
In all cases I don’t receive any text in the elements I am err, test, and test2 elements but i do get an alert window and there is text in the getEleTest element. What could be going on here. I don’t get any errors in the firebug console, the jquery is getting the ’email’ and ’email2′ elements. I’ve checked that I am linking the jquery script properly and just in case I haven’t I added the google jquery source. Thanks
Put all the jQuery stuff in
$(document).ready(function(){ //your code here });EDIT 2: I had a typo in my JS code. You were mixing regular JS with jQuery.
Why not write something like this?
and add id = “signUpForm” atribute to form? Also you need to remove inline JS from your HTML so your input doesn’t have onKeyUp event.
You can see my example here.