help with for loop

Results 1 to 3 of 3

Thread: help with for loop

  1. #1
    Join Date
    Dec 1969

    Default help with for loop

    On one of my webpages I&#039;ve generate a list of records from a database, every item has a checkbox (the name of the check box looks like : 1.check and 2.check etc). I also generate a hidden variable that specify the amount of items in the list. <BR><BR>I&#039;m trying to run a validate script that checks that atleast one of the checkboxes on the page is checked, otherwise it returns false.<BR><BR>In my for loop below I need to get a hold of the value for document.delnews."1.check".value and document.delnews."2.check".value etc Is this possible ?<BR><BR>function validate_delete()<BR>{<BR> var len = document.delnews.counter.value;<BR> var counter=0;<BR><BR> for(counter=0; counter &#060; len; counter++)<BR> {<BR> if (check if checkbox is checked)<BR> return true;<BR> }<BR> return false<BR>}<BR><BR>Appreciate any help.<BR><BR>Cheers :)

  2. #2
    Join Date
    Dec 1969

    Default Check out the documentation for...

    ...getElementById() on the Microsoft website:<BR><BR><BR><BR><BR>Oliver.

  3. #3
    Join Date
    Dec 1969

    Default ...alternatively...

    [code language="JavaScript"]<BR>function validate_delete(){ <BR> var len = document.delnews.counter.value; <BR> var counter=0; <BR><BR> for(counter=0; counter &#060; len; counter++){ <BR> if (document.delnews["1.check"].checked){ return true; }<BR> } <BR> return false;<BR>}<BR>[/code]<BR><BR>That&#039;s assuming you have NAMED your fields like:<BR>&#060;input type="checkbox" name="1.check" value="whatever" /&#062;<BR><BR>Craig.

Posting Permissions

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