Web Analytics Made Easy -
StatCounter seeing if checkboxes are checked - CodingForum

Announcement

Collapse
No announcement yet.

seeing if checkboxes are checked

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • seeing if checkboxes are checked

    I am having problems with this:

    Code:
    var day_time = (dayOfWeek+'.'+t);
     if(!document.myForm.day_time.checked) {alert("ARGH");}
    in that it doesnt substitite the value for day_time, rather just uses the string 'day_time'.

    (day_time is of the form "monday.am" which is also the NAME of a particular checkbox in my form.

    Can anyone help me please! Thanks.

  • #2
    document.getElementById(day_time)

    should work - make sure your checkbox's ID attribute is correctly entered, of course.

    Or you could just use eval("document.myForm."+day_time+".checked")

    but that's bad, apparently.

    Comment


    • #3
      sorry, day_time is ID of the checkbox, not the name DOH! does that mean there are any other ways to do it? I tried the ."+day_time+". like you said but i keep getting "unexpected identifier" errors .

      Thanks again!

      Comment


      • #4
        Sorry, getting a little confused. Does document.getElementById(day_time) not work then?

        Comment


        • #5
          yey!

          sorry, my mistake - i assumed that coz i said it was the name rather than the id, it wouldnt work - just tried it though and it works fine - thank you!! thats my stressful afternoon over with!!

          Comment


          • #6
            anytime

            Comment


            • #7
              Code:
              var day_time = (dayOfWeek+'.'+t);
              if(!document.myForm.elements[day_time].checked) {
                  alert("ARGH");
              }

              Comment


              • #8
                More info on square bracket notation.
                Glenn
                vBulletin Mods That Rock!

                Comment

                Working...
                X