Page load and checkbox value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lukelrc

    Page load and checkbox value

    Hi,

    I have a form on and ASP page that has a checkbox (chkAnyTheme) which
    disables a list box (txtListThemes) with an onclick event. I also have
    the follwoing code that checks if the chkAnyTheme is checked when the
    page loads and if so disableds txtListThemes:

    <script type="text/javascript">
    var IsChecked = document.getEle mentById("chkAn yTheme")
    if (IsChecked.chec ked)
    {
    document.getEle mentById("txtLi stThemes").disa bled = true
    alert("Checked is True")
    }
    </script>

    this works fine when the page is loaded from the server but i also
    need it to work if the user uses the back/forward button. At the
    moment the moment the script is not picking up if chkAnyTheme is
    checked and doesn't disable txtListThemes. Then if the user clicks on
    chkAnyTheme the on click code that disables txtListThemes gets
    confused and disables txtListThemes when chkAnyTheme is not checked
    and vice versa.

    I think that maybe when the page loads using the back/forward buttons
    the code is exectued before checkbox is assigned a value. Does anyone
    know a way of getting round this?
  • Lee

    #2
    Re: Page load and checkbox value

    Lukelrc said:
    [color=blue]
    >this works fine when the page is loaded from the server but i also
    >need it to work if the user uses the back/forward button. At the
    >moment the moment the script is not picking up if chkAnyTheme is
    >checked and doesn't disable txtListThemes. Then if the user clicks on
    >chkAnyTheme the on click code that disables txtListThemes gets
    >confused and disables txtListThemes when chkAnyTheme is not checked
    >and vice versa.
    >
    >I think that maybe when the page loads using the back/forward buttons
    >the code is exectued before checkbox is assigned a value. Does anyone
    >know a way of getting round this?[/color]

    Execute that code in the onLoad handler of the body.
    Then it won't look for the checkbox until after it has been set.

    Also, the code in the checkbox's onclick handler should check
    the current value, so it can never get confused.

    Comment

    • Luke Curtis

      #3
      Re: Page load and checkbox value

      Thanks, now it works fine!


      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      Working...