Olá pessoal, como vão?
Preciso de uma ajuda aqui, pois o meu código aparentemente está correto, mas o texto que resulta de uma mensagem de erro que deveria estar aparecendo num determinado
não está aparecendo onde deveria. O loop funciona, pois quando executo o código as mensagens são as devidas, porém fora de lugar. Segue código:
[img]http://s17.postimage.org/iddgjig7z/Screen_Shot_2012_07_02_at_11_26_24_AM.png[/img]
<html>
<head>
<title>My form</title>
<script type = "text/javascript">
function register(){
var x = new Array();
x[0] = document.getElementById('name').value;
x[1] = document.getElementById('lname').value;
x[2] = document.getElementById('email').value;
x[3] = document.getElementById('password').value;
x[4] = document.getElementById('cpassword').value;
var h = new Array();
h[0] = "<span style = 'color:red;'>Please type a name!</span>";
h[1] = "<span style = 'color:red;'>You must type a last name!</span>";
h[2] = "<span style = 'color:red;'>You must type a valid email!</span>";
h[3] = "<span style = 'color:red;'>You must type a password!</span>";
h[4] = "<span style = 'color:red;'>You must confirm a password!</span>";
var divs = new Array("mname","mlname","memail","mpassword","mcpassword");
for (i in x){
var error = h[i];
var div = divs[i];
if(x[i]==""){
document.getElementById(div).innerHTML = error;
}else{
document.getElementById(div).innerHTML = "OK!";
}
}
}
</script>
</head>
<body>
<h3>My Form</h3>
<form>
<table border="1">
<tr><td>Name:</td><td><input type="text" id="name" /></td><td><div id = "mname"></div></td></tr>
<tr><td>Last Name:</td><td><input type="text" id="lname" /></td><div id = "mlname"></div></td></tr>
<tr><td>Email:</td><td><input type="text" id="email" /></td><div id = "memail"></div></td></tr>
<tr><td>Password:</td><td><input type="text" id="password" /></td><div id = "mpassword"></div></td></tr>
<tr><td>Confirm Password:</td><td><input type="text" id="cpassword" /></td><div id = "mcpassword"></div></td></tr>
</form>
</table><br />
<input type="button" value="submit" onclick="register()" />
</body>
</html>