|
-
Mar 19th, 2003, 06:22 AM
#1
Thread Starter
Junior Member
onBlur
on my html page, I have one text box and one submit button.Text box has validation routine on its onBlur event. When I enter invalid text in text button and try to click submit button validation routine works fine and alert message is shown and form is not submitted. Submit button can also be called by Alt + G (I have set up code for hotkeys using javascript), but this time onBlur event is not invoked as focus remains on the text box.
how can I stop form from being submitted when user presses Alt+G with invalid text in text box. The page may contain multiple text boxes with onBlur events.
-
Mar 19th, 2003, 06:50 AM
#2
Lively Member
hi!
Insted of using a submit button you can use a normalbutton and
onthe mousedown event you call the validate function and
you also call this function from the Alt+G press
function validate()
{
valid = isvalid()
if(valid == true){
document.form.submit
}
}
-
Mar 20th, 2003, 07:00 AM
#3
Frenzied Member
I would do it a little differently, and use the onsubmit event handler of the form. This way you don't need to bother manually calling the function, and you only need to declare it once, and it will work regardless of whether the user pressed enter, clicked the button or whatever:
Code:
<script type="text/javascript"><!--
function validate(formElement) {
//ALL YOUR VALIDATE STUFF HERE -
// RETURN TRUE IF ALL IS OK
if (formElement.txt.value != '') {
return true;
}
//Only gets here if the form doesn't validate
return false;
}
//--></script>
<form action="page.php"
onsubmit="return validate(this);"><p>
<input name="txt" /><input accesskey="G" type="submit" />
</p></form>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|