March 24th, 2001, 01:52 PM
I'm just starting to write forms validation using jscript, and have done well so far. However, I have coded a function that checks most of the form fields (except radios) and alerts the user when I click the submit button. However, the focus remains on the submit button leaving the possibility for the user to submit the form anyway. How can I change the focus from the submit button to another object within the function?
March 24th, 2001, 03:08 PM
It could have something to do with the fact that I can't get my code to compile past the for statement.
moveto = "";
valU = document.forms(0).elements(i).value;
thing = document.forms(0).elements(i).name;
if(valU == "")
alert("Invalid Entry! Check: " + thing);
if(i < 90)
March 24th, 2001, 07:18 PM
Is there a way to keep a form from submitting even if the user presses enter within the form?
Can an object be removed from the tab order?
March 25th, 2001, 06:23 PM
not sure if you can remove an object from the tab order but you could take focus off an object if it becomes focused :-
March 27th, 2001, 09:26 AM
Removing and Object from Tab Order
Thanks Jonathon, I've figured out how to remove object from taborder. Just set <... tabindex="-1"). I just tried it and it worked!
However, I can't seem to get your idea to work for the submit button. No matter what I seem to do, I can hit Enter and the damn form submits anyway. I always loved that with IE, but now it is biting at my heels!
March 27th, 2001, 06:36 PM
One way would be to disable the submit button "<input type=submit name=submit value=submit disabled>" and validate the form fields as the user fills them out using the onchange or onblur events. When the user gets to the last form field and has correctly filled out all other fields you can enable the submit button "document.forms.submit.disabled=false" and the user will be able to submit the form.
If the user incorrectly fills out a field and tries to tab to the next field an alert can appear telling the user what the problem is... from a usability point of view this could be better than validating the form all in one go after the user has been over the whole thing and tried to submit it, might be friendlier to help the user fix incorrect entries as they happen.
March 30th, 2001, 03:45 AM
It sounds like you are attaching the validation scripts to each of the form elements. Why not just attach one to the main form tag? Then in your validation function return false if any of the validation fails -- this will prevent the form from submitting no matter what. Example,
<FORM onsubmit="return FormValidator(this)" >....