Register  |  Login



Earn money by sharing your knowledge through Quomon's revenue sharing program

Question

Status: Closed Points: 75 Time: 15:49 - Oct 30, 2007  

kassidi6

i need help with enabling/disabling text fields

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:

Answer Discussion
Tutorials

 

Q&A System for Websites and Corporate Collaboration

Advertisement

  • Generates significant organic traffic for websites
  • Saves companies money, resources, and time

kassidi6

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

kassidi6

Date:: Nov 07, 2007

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:

rcastagna: 75

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?

No tutorials have been submitted yet. Want to be the first?

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?

Ask a Question

Have a new question? Ask!

You have 100 characters to use



Top JavaScript Experts

View More

Rank

Expert

Points

1.

rcastagna

75

Become an Expert

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! Digg it



Language Options

English:

www.quomon.com

Español:

www.quomon.es