By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,459 Members | 1,208 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,459 IT Pros & Developers. It's quick & easy.

Page load and checkbox value

P: n/a
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.getElementById("chkAnyTheme")
if (IsChecked.checked)
{
document.getElementById("txtListThemes").disabled = 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?
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Lee
Lukelrc said:
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?


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.

Jul 23 '05 #2

P: n/a
Thanks, now it works fine!
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.