-
validation
If the user doesn't provide the name , an alert box should be displayed and the text box should get focus
And I want to perform the validation before going to the next page(log.asp),i.e before the log.asp page gets displayed.
I have used document.frm.txtbox_name.focus(); ,but that doesn't work
Can anyone help me with this?
<html>
<head>
<script language="JavaScript">
function show()
{
if (document.frm.txtbox.value=="")
{
window.alert("enter name");
document.frm.txtbox.focus();
}
}
</script>
</head>
<body>
<form name="frm" method="post" action="log.asp">
Name:
<input type="text" name="txtbox">
<input type="Submit" value="Enter Name" onClick="show()">
</form>
</body>
</html>
Regards
-
Re: validation
Your form tag should be:
HTML Code:
<form ... onsubmit="return show()">
Your show() function should be:
Code:
function show() {
if(document.frm.txtbox.value=="") {
alert("enter name");
document.frm.txtbox.focus();
return false;
}
return true;
}
Dr. Script