Thanks Bill ...but

Results 1 to 2 of 2

Thread: Thanks Bill ...but

  1. #1
    Join Date
    Dec 1969

    Default Thanks Bill ...but

    thanks for your help it worked like a charm....this is another function where I am adding a record to table if a user check on a checkbox then hit enter button it will alert ....the problem is it work fine if I check one record or as many as I want but if I check all the records in table than it will submit....<BR>any ideas why it is failing there<BR>thanks again<BR><BR><BR>function AddData()<BR>{<BR>if (document.adminform.rowid.length &#062; 1) <BR> {<BR> var Checkboxlength = document.adminform.rowid.length;<BR> var checkFlag = false;<BR> var uncheckFlag = false;<BR> for(j =0; j &#060; Checkboxlength; j ++)<BR> {<BR> if(document.adminform.rowid[j].checked == false)<BR> checkFlag = true;<BR> else<BR> uncheckFlag = true;<BR> }<BR> }<BR> if(checkFlag == true && uncheckFlag == true)<BR> {alert("Please select at least one item to Delete by checking the box.");<BR> }<BR> else<BR> { document.adminform.action = "admin_maintainTableRecord.asp"<BR> document.adminform.submit();<BR> }<BR>}<BR>

  2. #2
    Join Date
    Dec 1969

    Default Same kind of logic error...

    Why are you against simply *COUNTING* the number of checkboxes, as I did in my code???<BR><BR>Look at your code:<BR><BR>for(j =0; j &#060; Checkboxlength; j ++)<BR>{<BR>&nbsp; &nbsp; if(document.adminform.rowid[j].checked == false) checkFlag = true;<BR>&nbsp; &nbsp; else uncheckFlag = true;<BR>}<BR>if(checkFlag == true && uncheckFlag == true)<BR>{<BR>&nbsp; &nbsp; alert("Please select at least one item to Delete by checking the box.");<BR>} else { <BR>&nbsp; &nbsp; document.adminform.action = "admin_maintainTableRecord.asp"<BR>&nbsp; &nbsp; document.adminform.submit();<BR>}<BR><BR>Now look CAREFULLY at what happens if *EVERY* checkbox is checked. *WHEN* does the "uncheckFlag" ever get set to true in that case???<BR><BR>Answer: NEVER! <BR><BR>Now look at your "if" code. When is the alert box *NOT* displayed? When *either* the checkFlag *OR* (!!!) the uncheckFlag is *not* set true, right?<BR><BR>Okay, so if you check all the boxes and the uncheckFlag is not set to true...Well, what do you expect? OF COURSE it then does the submit!<BR><BR>And if *NONE* of the boxes are checked, *then* what happens? When is the checkFlag ever set to true? <BR><BR>Answer: NEVER!<BR><BR>So the same thing applies.<BR><BR>So the *only* time you get a nasty alert from that code is when you check at least one checkbox but don&#039;t check all of them. Your code is saying "accept either zero or all, but nothing else."<BR><BR>Again, I ask: Why not just use a counter? In this case, if the counter is zero, you reject the request with an alert. If it is non-zero, you go do the delete.<BR><BR>Learn to step through your code one line at a time, using an example. And learn to use every possible combination of values in your example. Time and patience...and pretending to be the computer...are the secrets.<BR><BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts