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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy problem with function

Status
Not open for further replies.

runcsmeduncs

Programmer
Aug 10, 2004
5
GB
Hello

I am fairly new to JavaScript so bare with me on this one.

My function looks like this:

<script language="JavaScript" type="text/JavaScript">
function checkForm(theForm){
box1 = frmHR.p_update;
box2 = frmHR.p_hr_update;
if(frmHR.p_update.length){
for (i=0;i<box1.length;i++){
if (box1.checked && box2.checked){
alert("You cannot select both");
box1.focus();
return false;
}
}
}
else
{
if (box1.checked && box2.checked){
alert("You cannot select both");
return false;
}
}
return true;
}
</script>

very simply all it does is a bit of validation on my form which has 20 rows. 1 or many of the rows can contain 2 checkboxes "p_update" and "p_hr_update". This check just makes sure that the user cannot check them both.

My function works fine when there is one or more rows containing these checkboxes on the form but generates an error when there are no rows on the form with the 2 checkboxes.

All i am trying to do is modify the function to return true when there are no checkboxes on the form with the name "p_update" and p_hr_update".

Hope someone can help.

Regards

Duncan
 
Ok, first the function requires a value 'theForm' yet I do not see where it is referenced inside the function. I suggestion when calling the function you pass a reference to it and use that reference within the function.

Before checking to see if a box is checked, determine if there is a checkbox. Don't assume there will always be a checkbox.

Finally, what are you checking to see if the box is checked? The value of a checkbox can be something other than yes/no true/false.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top