SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to uncheck a checkbox

    I am sure this must a very old question, but I cannot find the answer. I have a form where I want the address box to appear if the user ticks the checkbox called "Please send a catalogue". The form is at

    http://www.pfwd.co.uk/bounceabouts/contact-us.htm

    The relevant code has the comment immediately above it <!--Please send catalogue-->

    The checkbox has onclick="toggleDisplay('address'); which works nicely. The Javascript function is near the top of the page.

    Near the bottom of the page is address.style.display = 'none'; which makes the address box invisible to start with.

    My problem starts if the user clicks Refresh. The address box disappears once more but the checkbox stays checked. This is overcome by adding at the bottom catalogue.checked = ''; so that the checkbox is set back to unchecked on refreshing. Catalogue is the name of the checkbox. This works in Firefox, Opera and Netscape, BUT not in IE7, which says that there is an error: catalogue is undefined.

    Can someone suggest to me how to get Internet Explorer to do the same as the others please?
    Last edited by Pelias; May 17, 2007 at 02:49. Reason: No replies yet!

  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Put it in the body tag:
    Code:
    <body onload="document.getElementById('catalogue').checked = '';">
    or
    Code:
    <body onload="catalogue.checked = '';">

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    That works

    Thank you very much. That works.

    But, interestingly, only the first of the two suggestions worked for me. The second, shorter, one still had IE7 giving the error "catalogue is undefined".

    Peter Finch

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My mistake, the second one should be:
    Code:
    <body onload="document.yourformname.catalogue.checked = '';">

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, that one works for me as well.


Bookmarks

Posting Permissions

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