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

check box enable/disable

P: n/a
i want to enable one listbox and disable the other depending on if i
check winter_gala (checkbox)

here is my code.
<script type="text/javascript">
function check()
{
if (document.forms.winter_gala.checked=true)
{
document.forms.winter_gala.young_friend_list.disab led=true
document.forms.winter_gala.dual_young_friend_list. disabled=false
}
else if (document.forms.winter_gala.checked=false)
{
document.forms.winter_gala.young_friend_list.disab led=false
document.forms.winter_gala.dual_young_friend_list. disabled=true
}
}
</script>

Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
wrote on 27 dec 2004 in comp.lang.javascript:
i want to enable one listbox and disable the other depending on if i
check winter_gala (checkbox)

here is my code.
<script type="text/javascript">
function check()
{
if (document.forms.winter_gala.checked=true)
{
document.forms.winter_gala.young_friend_list.disab led=true
document.forms.winter_gala.dual_young_friend_list. disabled=false
}
else if (document.forms.winter_gala.checked=false)
{
document.forms.winter_gala.young_friend_list.disab led=false
document.forms.winter_gala.dual_young_friend_list. disabled=true
}
}
</script>
I fail to read a question in your posting.
Doesn't it work? do you gat an error?
What error on what row?
;-)

========================
if (document.forms.winter_gala.checked=true)
[(document.forms.winter_gala.checked=true) SETS the value to true,
and always returns true]

should be ["==" is comparison, "=" is assignment]:

if (document.forms.winter_gala.checked == true)

but testing a boolean value against true is superfluous, so:
if (document.forms.winter_gala.checked)
========================
else if (document.forms.winter_gala.checked=false)


this is [after correcting to "=="] the same as simply:

else

========================

I fail to see how

forms.winter_gala

can be both a checkable element and the parent of

young_friend_list

Correct for that!

========================

then try:
<script type="text/javascript">
function check() {
var temp = document.forms.winter_gala //see objection
var temp1 = temp.young_friend_list
var temp2 = temp.dual_young_friend_list
if (temp.checked) {
temp1.disabled = true
temp2.disabled = false
} else {
temp1.disabled = false
temp2.disabled = true
}
}
</script>

===========================

or even shorter and IMHO more clear:

<script type="text/javascript">
function check() {
var temp = document.forms.winter_gala //see objection
var temp1 = temp.young_friend_list
var temp2 = temp.dual_young_friend_list

temp1.disabled = temp.checked
temp2.disabled = !temp.checked
}
</script>

Not tested, since no HTML.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.