-
Default Button
Hi all,
I understand that if I put a submit button on a page, that button becomes the default button (ie, just press enter and the submit button activates)
However, if i want to do some validation before I submit the form, I use an input=button. However, when I do that, that button doesnt receive the focus automatically and the use has to manually click on it.
The Q is, how do i enable the default status of a button just like it were a submit button ?
Thanks.
-
HI SoftwareMaker,
You dont really have to use input button, you can use submit button to do your validation.
this is how i do my validation on most forms
Code:
<html>
<head>
<script>
function validate()
{
if (some condition)
{
alert(msg);
return false;
}
if (another condition)
{
alert (msg);
return false;
return true;
//if the functions returns true then the form will
//be submited otherwise the form wont be submited
}
</script>
<body>
<form action="submit.asp" onsubmit="return validate()">
</form>
</body>
</html>
Hope this helps
Danial
-
Normally I used this codes to do the form focus and validation as well:
Code:
<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
<!--
Sub window_onload
Login.txtLogin.focus()
End Sub
Sub submit1_onclick
if len(login.txtPassword.value) < 6 then
Login.txtPassword.value = ""
msgbox "Password too short!"
exit sub
end if
login.submit()
End Sub
-->
</SCRIPT>
-
Thanks guys for your tips.
Thanks Daniel...so you are saying that once the function return false, the form wont get submitted ?
-
Hi daniel,
I am sorry BUT it seems to me that the input type=submit doesnt have a onsubmit event, so how now ?
Thanks
-
OOppps...Sorry my fault,
I put on my glasses and actually saw that it is a form event not an input event. Sorry...