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!

javascript deletion warning message 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)
THANKS


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;
}

}
 
Javascript would be a more appropriate forum for this...

I have encountered such a problem before..

All you have to do is, if maxi is = 1, ie which means only one box is checked you SHOULD NOT refer it like an array..rather refer that as a single check box...

Try something like this
Code:
if (maxi>1)//iterate only if more than 1 check box is displayed..
 for (var idx = 0; idx < maxi; idx++)
    {
            if (eval(&quot;frmDeletion.list[&quot; + idx + &quot;].checked&quot;) == true) 
            {
                total += 1;
                
               }
    }

Try this technique..
Let us know.. Thank you...
RR

 
Thanks for your help but it does not work. The following script:
{alert(&quot;Number of checkboxes = &quot; + &quot; &quot; + maxi);} is just like a message box that I displayed for myself to see the value of &quot;maxi&quot; which is undefined when there is only one box left. When I do if (maxi>1), it automatically jumps to the else statement:
else{
alert (&quot;Checkbox not checked&quot;);
return false;
}
as if no checkbox was checked. I also tried to add 1 to maxi (if maxi == &quot;undefined&quot; or if maxi ==0 ...) but nothing works.


 
if (eval(&quot;frmDeletion.list[&quot; + idx + &quot;].checked&quot;) == true)

looks to me like you should be able to ask:

if (frmDeletion.list[idx].checked == true)

In theory, you really shouldn't have to ask == true either but I don't know if it's me or what, but sometimes that doesn't work properly, so I just qualify it with == true and it doesn't go wrong.

hope that helps! :)
Paul Prewett
penny.gif
penny.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top