Jump to content

Form validation


Guest Thomas

Recommended Posts

Hi,let me try to tell my problem: I have a form with textfields named field1id with a corresponding field named field1name, then another row with field2id and field2name and so on up to field10id and field10name. Now, I want to force the user to fill in the "name" if the "id" has a length >3 (default is one space), means, if he writes an id he MUST fill the name as well. I don´t want to annoy him with an alert/msgbox every time but an optical hint (colored border?) and last not least it needs to be checked onSubmit.Can anyone please help me out, I don´t get it.Thanks in advance,cheers, thomas

Link to comment
Share on other sites

well, you can have a onkeypress event for each id that will check if the id has anything in it and if it does, check the corresponding name and change the borders accordingly. As for onsubmit, if you check for errors and find some, you would want to return false to make sure the form doesn't get sumbitted.Hope that answers your question

Link to comment
Share on other sites

for the colored border, use document.getElementById("field_id").style.borderColor="#FF0000" for a red border, for example...and on the onkeypress, call a function that verify the document.getElementById("field_id").value.length, if its >= 3 you change the color of the border, else you turn it back to the original color...maybe you can change the size of the border also, but it can deform your formif you need some more specific code, just ask...but i hope you can solve your problem now

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...