Select Categories Below
Advertisement
Start Your Own Q&A Site
Create your own Q&A site easily, allowing you to quickly grow a new community around any subject matter or generate new organic traffic for your existing website.
Status: Closed Points: 75 Time: 15:49 - Oct 30, 2007
kassidi6
I looked at one your older posts and im currently using your following script: <html> <head> <title>Test</title> <script type="text/javascript"> function disable_controls( state) { var frm = document.forms[0] ; var len = frm.elements.length ; var cnt = 0 ; for ( var i=0; i < len; i++) { var elem = frm.elements[i] ; if (elem.type != "hidden") { elem.disabled = state ; } } } </script> </head> <body> <button onclick="disable_controls( false)">Enable</button> <button onclick="disable_controls( true)">Disable</button> <br> <form action="yours" method="POST" enctype="application/x-www-form-urlencoded"> <input name="t1" disabled size="10" value="ini val" type="text"> <br> <textarea name="t2" cols="10" disabled >abc def</textarea> </form> </body> </html> -------------------------------------------------------- The way i'm actually using it is instead of using buttons to disable/enable the following fields, i'm using a radio type field. Yes (is the Enable value) and No (Disable value). The problem i'm having is that when i a select No, it will gray out radio field. I can't then go back and select Yes. I tried tweaking the code a bit, but with no success. Is there a way to workaround this? Thank you very much.
Categories:
Add Categories
When adding more than one category, separate them with commas.
Date:: Oct 30, 2007
Time:: 16:05
oops, i forgot to mention that i changed the code of the html body to be as follow: -------------------------------------------------------------------------------------------- <body> <form action="yours" method="POST" enctype="application/x-www-form-urlencoded"> <input type="radio" value="Yes" name="Marketing_IC_Contact_Info__em" onclick="disable_controls( false)">Yes <input type="radio" value="No" name="Marketing_IC_Contact_Info__em" onclick="disable_controls( true)">No <br> <input name="t1" disabled size="10" value="ini val" type="text"> <br> <textarea name="t2" cols="10" disabled >abc def</textarea> </form> </body> ---------------------------------------------------------------------------------------------------------------- The reason it's behaving the way i mentioned earlier is because i moved the radio field inside the form, which is how we want it to be. Any help on how to get it to work by having the radio field inside the form will be much appreciated. Thank you.
rcastagna
Date:: Nov 07, 2007
Time:: 07:35
kassid, In your javascript, you're iterating through all the controls and disabling them, including your radio button. That's why it's giving you the behavior you're experiencing. Basically, you're still going to iterate all the controls in the form, but when you get to your radio button(s), you're going to leave them enabled by ignoring them... if (elem.type != "hidden") { if (elem.type != "radio") { elem.disabled = state ; } } That will keep all radio buttons enabled. You can refine it by looking at the name or adding an id property and excluding the radio button(s) programmatically. I hope this helps, Ric
Time:: 16:46
missed that. works out fine now. Thank you.
Question Answered
This question has been closed, and points have been rewarded to the following experts:
You're welcome however to comment or give additional information or if you wish, you have the ability to write a Tutorial in the Tutorial Area.
Answer this Question
New User
Email:
Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address
Registered User
Username:
Password:
Forgot Your Password?
Enter your email address below and we will resend your login information to you.
Login Information Sent
Questions
Need help with enabling/disabling only few text fields in the form
You have 100 characters to use
Rank
Expert
Points
1.
10279
2.
6493
3.
5596
4.
4848
5.
3487
6.
2840
7.
2770
8.
2303
9.
1820
10.
917
Register today to share your knowledge with the community and be recognized and rewarded for your contributions.
Register Here
"Psst, Quomon is a great site. Pass it on." Tell a Friend | Link To Us | Save to Delicious | Digg it
Language Options
English:
Español:
Sponsors
Questions and Answers Software