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

deletion pb!

Status
Not open for further replies.

diarratech

Technical User
Jul 7, 2000
41
0
0
FR
"list" is a check box on a form.
This script is supposed to check if a user selected a check box or not before deletion. It works great except when there is only one check box left. Javascript sees the value of the check box as "undefined."
(I used that script to delete rows on a form)
The following script:
{alert("Number of checkboxes = " + " " + maxi);} is just like a message box that I displayed for myself to see the value of "maxi" which is undefined when there is only one box left. When I try if (maxi>1), it automatically jumps to the else statement:
else{
alert ("Checkbox not checked");
return false;
}
as if no checkbox was checked. I also tried to add 1 to maxi (if maxi == "undefined" or if maxi ==0 ...) but nothing works.

Here's the script



function confirmSubmit()
{
var total = 0;
var maxi = frmDeletion.list.length;


{
alert("Number of checkboxes = " + " " + maxi);
}

for (var idx = 0; idx < maxi; idx++)
{
if (eval(&quot;frmDeletion.list[&quot; + idx + &quot;].checked&quot;) == true)
{
total += 1;

}
}


if (total > 0)
{
alert(&quot;Total checkboxes checked =&quot; + &quot; &quot; + total);
var agree=confirm(&quot;Do you want to delete &quot; + total + &quot; row(s) ?&quot;);
if (agree)
{
return true ;
}

else
{
return false ;
}
}
else
{
alert (&quot;Checkbox not checked&quot;);
return false;
}

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top