• Notice regarding image hosts and attachments. See here.

JavaScript Validation Help

Soldato
Joined
30 Nov 2005
Posts
3,086
Location
London
Anyone know why this won't work.

Seems all valid to me.

Oh and yes I know it's old school JavaScript, it's a legacy form.

PHP:
			{
var chks = document.getElementsByName('previous');
var checkCount = 0;
for (var i = 0; i < chks.length; i++)
{
if (chks[i].checked)
{
checkCount++;
}
}
if (checkCount < 1)
{
alert("MESSAGE 1 GOES HERE.");
return false;
}
		}
		
if(contactform.previous[0].checked){
if(contactform.refnumber.value.length==0||contactform.refnumber.value==" "){ alert("MESSAGE 2 GOES HERE"); contactform.refnumber.focus(); return false;}
}
 
Ok just had a look through the code, it's a mess btw, and it would seem there was two separate functions of the same name, being run when the onsubmit="return etc etc" was run.

So I removed one of them and the above now works.

But really need to get that piece of validation back in, which is this:

PHP:
if (!document.contactform.CODEnumber.disabled) { 

var re1letter4digit=/(?:[a-zA-Z])\d{4}/ //regular expression defining a 5 digit number
if (document.contactform.CODEnumber.value.search(re1letter4digit)==-1) { //if match failed
alert("Please enter a valid CODE number.");
return (false);

}
}

I've tried inserting the above code into the original function (which the one in my first post is in) but it won't run the above.
 
The script as a whole runs, but it doesn't alert if the user doesn't enter a number that the regex expression states is required.

It's so confusing.

It's for a field box that isn't enabled as default, the field box only becomes available to enter information when a user checks a tickbox.
 
Back
Top Bottom