check box enable/disable

V

vncntj

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.disabled=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.disabled=false
document.forms.winter_gala.dual_young_friend_list.disabled=true
}
}
</script>
 
E

Evertjan.

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.disabled=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.disabled=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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top