Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validating fields in forms

Status
Not open for further replies.

MarcLodge

Programmer
Feb 26, 2002
1,886
0
0
GB
All,
I posted this in the JavaScript forum earlier today, but I'd post it here too to see if anybody can help....

I am trying to validate a number of mandatory fields on a form. Most of these are text fields, but I also have a couple of radio buttons and one checkbox which can have more than one value ticked. The existing script, which I must admit is not mine, caters for blanks in the mandatory text fields great, but I just cannot get it to process the radio buttons or checkboxes. I've tried adding to the end of the script, but it just seems to ignore it, or more probably, never get there. I've put in debuggin ALERT messages, but just do not have enough knowledge to crack it. I can see I'm going to have to go and buy a book and learn this JS stuff properly rather that knock it up on the fly. Any help that you can give will be greatly appreciated.
Script is:

function checkforblanks()
{
for (var i = 0; i < arguments.length; i += 2)
{
if (!arguments)
{alert(&quot;Please enter &quot; + arguments[i+1] + &quot;.&quot;);return false;}
}
return true;
}

function validate()
{

// Make sure none of the required fields are empty
var isFull = checkforblanks(document.myForm.fname.value, &quot;your first name&quot;,
document.myForm.lname.value, &quot;your last name&quot;,
document.myForm.addr1.value, &quot;the 1st line of your address&quot;,
document.myForm.town.value, &quot;your town&quot;,
document.myForm.county.value, &quot;your county&quot;,
document.myForm.pcode.value, &quot;your postcode&quot;,
document.myForm.phone.value, &quot;your phone number (including std code)&quot;,
document.myForm.email.value, &quot;your e-mail address&quot;);
if (!isFull)
{return false;}

}
 
can you also post the html page with your form elements
thanks
 
Salshaikh,
Thanks for your interest, but I went out and bought a book on Javascript! I've done it a different way, which is all helping me to learn.
Thanks again
Marc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top