0

Hi everyone,

I've whipped up a simple validation script to vaildate simple form elements.

My issue is when i submit the form without any data it works correctly. It catches on each individual element and reports the error.

When the fields are populated correctly, i am receiving an error message in firebug stating that myForm is undefined.

is this something to do with the way in which getElementByID functions or is my code out of whack ?


also from this function i would like to know how i can make it return so if my button has additional function call appended to it, it will begin to function the addtional request.

<input type="button" onclick="return validateForm('myDeliveryForm'); loadnext(1,2);">

as you can see there are 2 functions being called when the button is hit... what would be required in my code below to let the browser return the next function ?

function validateForm(args,len)
	{
		var myForm = document.getElementById(args) ;

		for( i=0 ; i<=document.getElementById(args).length ; i++ )
			{
				if(myForm[i].getAttribute('required') == 'true' && myForm[i].value == '')
				{
				alert(myForm[i].getAttribute('message'));
				myForm[i].focus();
				return false;
				}
			}
		return true ;
	}
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by sysel
0

Sorry, I cannot be sure without see the <FORM> definition, but suppose, that the mistake is hidden here: the DOM object myForm subobjects must be called: myForm.childNodes

Nice day (or night) :-)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.