What is wrong with this

Results 1 to 3 of 3

Thread: What is wrong with this

  1. #1
    Join Date
    Dec 1969

    Default What is wrong with this

    I want to have a link to check all check boxes of a certain name (which I have). But once the link is clicked once, I want them to be able to click it again to uncheck all the boxes, this is what I have.<BR><BR>&#060;script language="JavaScript"&#062;<BR><BR>var allchecked<BR><BR>function checkAll(field)<BR> {<BR> for (i = 0; i &#060; field.length; i++)<BR> field[i].checked = true ;<BR> allchecked = true ; <BR> }<BR> <BR> function uncheckAll(field)<BR> {<BR> for (i = 0; i &#060; field.length; i++)<BR> field[i].checked = false<BR> allchecked = false ;<BR> }<BR> if (allchecked == undefined) {<BR> allchecked = false<BR> }<BR> <BR> if (allchecked)<BR> {<BR> document.write("&#060;a href=javascript:uncheckAll(document.videos.ids)&#0 62;Chk&#060;/a&#062;") ;<BR> }<BR> else<BR> {<BR> document.write("&#060;a href=javascript:checkAll(document.videos.ids)&#062 ;Chk&#060;/a&#062;") ;<BR> } <BR> &#060;/script&#062;<BR><BR>the var allchecked DOES get turned to true once the link is clicked, but the if statement that writes ths link writes the link to check all no matter what the value of allchecked is<BR><BR>???

  2. #2
    Join Date
    Dec 1969

    Default I assume a click on the link...

    ...means a round trip to the server - or am I missing something in your code? In this case, guess what happens to the client-side variable allchecked.<BR><BR>Why don&#039;t you avoid the round trip and stay on the page? Or do you need to go back to the server to check or update a database or something?<BR><BR>Oliver.

  3. #3
    Join Date
    Dec 1969

    Default Would be easier...

    To have one function do both things, then you only need one link (which you can hard code) that will work, instead of having to write out a new link, every time someone decides they want to check/uncheck the boxes.<BR><BR>Just my .02

Posting Permissions

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