Jump to content

looping through form elements


Recommended Posts

HiI'm trying to find an easier way of validating some form values, by looping through the form values.I have a validation function that when the submit button is clicked the entire form is passed to the function.

function Validate(theForm){		checkForPresets(theForm);	}

This calls and passes again the form to this other function:

function checkForPresets(formValues){var presets = new Array("Value1","Value2","Value3");elem = formValues.elements;var check = 0;	for(i=0;i<elem.length;i++){		for(x=0;x<presets.length;i++){			if(elem[i].value == presets[x]){				check++;							}		}	}alert("Amount of presets found: " + check);}

At the moment I'm using the alert box just for testing how many times the form values occur within the 'presets' array.In the form inputs I have preset values just to show the user how to fill out the form, and would utimately like to check for these preset values and let the user know that they have forgotten to fill out the values correctly.ie a preset value like "Enter your name here" would set off an alert to the user that they had forgotten their name.Some pointers in the right direction would be helpful.

Link to comment
Share on other sites

Dont worryFixed it, well solved it.Quite stupid really, been using a html page that calls this external function for a couple of hours, had it slightly working earlier on and forgot that I had made a another version of the page on the server.When I tried to recall the page using another page for testing I forgot that the page that I've called is not the page that I'm actually working on, so the javascript function in another external file also renamed does nothing to the old page. Looks the same but different name, this function now works fine as is, just got to rework it to do what I actually want it to do.I'm now going to take out my two false eyeballs and leave them in ice water overnight to cool down. :)

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...