Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 24th, 2006, 04:36 PM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default Enable/Disable Form Elements Question

I'm using JavaScript set the disable property on a textbox if a checkbox is selected, like this:

<input type="checkbox" name="cbquestion1" id="cbquestion1" onclick="javascript:document.form1.txtanswer1.disa bled=false">What is the name of your favorite pet?</input>
<input type="text" id="txtanswer1" name="txtanswer1" value="" size="20" maxlength="20" disabled="true" />

It works great, but now I'd like to add a behavior will basically do the opposite so that if the checkbox is then de-selected after initially being selected, it will re-disable the textbox. If anyone knows how to do this, I'd greatly appreciate the help. Thanks.

KWilliams
Reply With Quote
  #2 (permalink)  
Old February 24th, 2006, 05:27 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

This will toggle the state on each click:
Code:
onclick="document.form1.txtanswer1.disabled = !document.form1.txtanswer1.disabled
The javascript: preceeding the code is wasted.

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #3 (permalink)  
Old February 24th, 2006, 06:30 PM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi joe,

I tried that suggestion, but it just kept the textbox disabled whether or not the checkbox was clicked or not. Since this is in an XSLT doc, this is how I applied your suggestion:

<input type="checkbox" name="cbquestion1" id="cbquestion1" onclick="javascript:document.form1.txtanswer1.disa bled=false!javascript:document.form1.txtanswer1.di sabled=false">What is the name of your favorite pet?</input>
                        <input type="text" id="txtanswer1" name="txtanswer1" value="" size="20" maxlength="20" disabled="true" />

...and I also tried changing the 2nd JS instance to this:

onclick="javascript:document.form1.txtanswer1.disa bled=false!javascript:document.form1.txtanswer1.di sabled=true">

and of course I tried using the exact code that you included, but it still doesn't work. Any other suggestions?

KWilliams
Reply With Quote
  #4 (permalink)  
Old February 24th, 2006, 07:38 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well XSLT or not that's the correct code. What is the HTML that your XSLT produces?

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #5 (permalink)  
Old February 28th, 2006, 11:28 AM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I made a mistake by including this code in the onclick event:
onclick="javascript:document.mycounty_reg.txtanswe r1.disabled=false!document.mycounty_reg.txtanswer1 .disabled=false
...instead of the exact code that you supplied:
onclick="document.mycounty_reg.txtanswer1.disabled = !document.mycounty_reg.txtanswer1.disabled

Sorry about that. I just needed to change "disabled=false" to "disabled", and it worked great. Thanks again for your help Joe:)

KWilliams
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Enable / Disable Form Fields Automatically jackyam Javascript How-To 10 March 17th, 2008 04:46 AM
Disable/Enable elements ldoodle Javascript How-To 3 June 7th, 2005 05:48 AM
Question on dynamic changes to other form elements savoym Javascript 1 October 27th, 2004 10:17 AM
Disable Form Elements Hotwax ASP.NET 1.0 and 1.1 Professional 2 October 31st, 2003 08:11 AM



All times are GMT -4. The time now is 02:30 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.