Reply LinkBack Thread Tools Search this Thread
Old 08-06-2006, 06:37   #1 (permalink)
stealthcow
knocking heads
 
stealthcow's Avatar
 
Join Date: Jul 2003
Location: Liverpool, UK
Posts: 1,963
javascript enable/disable form field

I'm having problems enabling a form field once its been disabled, i have written the following javascript code:

menuID being the field i want to disable, and test being a checkbox

Code:
function disableField(menuID,test) { if(document.getElementById(test).checked == true) { document.getElementById(menuID).disabled = "true"; } else { document.getElementById(menuID).disabled = "false"; } }

any ideas?
  Reply With Quote
Old 08-06-2006, 09:51   #2 (permalink)
stickmus
hmmm...
 
stickmus's Avatar
 
Join Date: Jan 2004
Location: Yorkuk
Posts: 2,127
Try it like this:

disabled = "disabled"; // for disabled
disabled = ""; // for enabled
__________________
George Smith - a vain attempt to get higher on google for my name

  Reply With Quote
Old 09-06-2006, 05:21   #3 (permalink)
Bill Posters
trouble free and loverlee
 
Join Date: Mar 2003
Location: YooKay
Posts: 2,967
Both the checked and disabled properties take boolean values (true or false, though not as string literals, so they shouldn't be in quotes).

e.g.
Code:
obj.disabled = true //not obj.disabled = 'true'

This means that the process can be simplified by setting the disabled value to the checked value.

i.e.
Code:
function disableField(menuID,test) { document.getElementById(menuID).disabled = (document.getElementById(test).checked); }
When checked is true, disabled is set to true. When checked is false, disabled is set to false.
  Reply With Quote
Old 09-06-2006, 13:10   #4 (permalink)
smallbeer
I Ain't Losing Any Sleep™
 
Join Date: Apr 2003
Posts: 5,206
holy fucking crap batman!
  Reply With Quote
Old 09-06-2006, 13:44   #5 (permalink)
cam
vague™
 
cam's Avatar
 
Join Date: Mar 2004
Location: Glasgow
Posts: 5,595
haha.
__________________
  Reply With Quote
Old 09-06-2006, 13:48   #6 (permalink)
tomson
Balls in a biscuit tin
 
tomson's Avatar
 
Join Date: May 2003
Posts: 3,365
Bill Posters
Lover free and troublesome.


I thought he was dead.
  Reply With Quote
Old 09-06-2006, 19:41   #7 (permalink)
Scott
sanddancer
 
Scott's Avatar
 
Join Date: Feb 2004
Location: South Shields
Posts: 2,998
Send a message via MSN to Scott
we all thought you were dead..^
__________________
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8