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!

Problems with Checkboxes 1

Status
Not open for further replies.

garfield11

IS-IT--Management
Jul 4, 2002
44
0
0
SG
Hi all,

Below r javaScript codes to check all/clear all checkboxes:

<SCRIPT LANGUAGE = &quot;JavaScript&quot;>
<!--
function SetChecked(val, chkboxname) {
dml=document.forms[0];
len = dml.elements.length;
var i=0;
for( i=0 ; i<len ; i++) {
if (dml.elements.name == chkboxname)
dml.elements.checked = val;
}
}
//-->
</script>

<a href=&quot;javascript:SetChecked(1, 'Employee_ID')&quot;>Check All</a> - <a href=&quot;javascript:SetChecked(0, 'Employee_ID')&quot;>Clear All</a>

<input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Next ->&quot;>


Now i want my program to work like if none of the checkboxes are check, don't submit the form (that's when i click the &quot;Next&quot; button, no action perform).

Can anyone please kindly advise.

Thanks!

Love_Garfield
 
:: task: if none of the checkboxes are check, don't submit the form.

Add this function:

function checkboxValidation()
{
errorflag = false;
f = document.formName;

for (n=0; n<f.elements.length; n++)
if (f.elements[n].type == &quot;checkbox&quot; && !f.elements[n].checked)
errorflag = true;

return errorflag;
}

And run it on form submit event:

<form ... onsubmit=&quot;return checkboxValidation()&quot;>
 
Hi starway,

I've added this to my codes, but it doesnt seem to work...
when i click &quot;next&quot; button it still redirects to the next page.


Love_Garfield
 
hey, i got it already!

Thank u very much!

Love_Garfield
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top