HTML
<form action="./Login.php" method="post" onsubmit="return checkInput();">
<table width="300" border="1">
<tbody>
<tr>
<th> UserName: </th>
<td><input class="box" type="text" value="" name="uname" id="uname"></td>
</tr>
<tr>
<th>Password: </td>
<td><input class="box" type="password" value="" name="pword" id="uname"></td>
</tr>
</tbody>
</table>
<input type="hidden" id="infoDis" value=""/>
<input type="submit" value="Log-in" name="login">
<input type="submit" value="Reset" name="reset">
</form>
JS
function checkInput()
{
var v1 = document.getElementsByName("uname");
var v2 = document.getElementsByName("pword");
var uname = v1[0].getAttribute("value");
var pword = v2[0].getAttribute("value");
if (uname == "" || pword == "")
{
if(uname == "" && pword != "")
{
alert("Error: Username is Empty. Please Enter Username.");
}
else if(pword == "" && uname != "")
{
alert("Error: Password is Empty. Please Enter Password");
}
else
{
alert("Error: Username And Password is Empty. Please Enter Username and Password");
}
location.reload();
return false;
}
return true;
}
Hi guys. I am new to html/js. I having a small issue where when i enter new values into the textbox. It does not being captured by the javascript. In turn, after a few debugging i found that the javascript is always taking the value in the html tag. Hence, even if value is entered in the first try or in the retry phase, the javascript takes the value in the html "" tag. Please Help Thx.