0

Depending on which option I choose in the above drop down box, it is supposed to either gray the text boxes out, or let the user type in them. I am using the following:

document.getElementById(\'freq2\').disabled=true;

This does not work. But, I can use the following just fine, and it successfully disappears:

document.getElementById(\'freq2\').style.display = \'none\';

Why can I not gray out the text boxes, but I can hide them, and change their colors, etc.?

11
  • 3
    The property is disabled, not disable Commented Jul 11, 2013 at 19:13
  • Sorry, that it was I have. It is not working. Will edit above. Any other tips? Commented Jul 11, 2013 at 19:14
  • It's working here: jsfiddle.net/6A8Zd Why are you escaping the quotes? Are these statements part of another string? Commented Jul 11, 2013 at 19:20
  • 2
    Why are your quotes escaped? That's the problem. Commented Jul 11, 2013 at 19:20
  • 1
    So have you confirmed that the quotes are output in the rendered source correctly? Commented Jul 11, 2013 at 19:23

3 Answers 3

1

You need to unescape your quotes.

document.getElementById(\'freq2\').disabled=true;

needs to be

document.getElementById('freq2').disabled=true;

or the JavaScript won't be valid, so it won't disable it.


You can wrap multiple textboxes in a fieldset

<fieldset id="myfields" disabled="disabled">
    <input type="text" />
    <input type="text" />
</fieldset>

JavaScript:

document.getElementById("myfields").disabled = true;

CSS to remove border:

fieldset {
    border: 0;
}

JSFiddle

Sign up to request clarification or add additional context in comments.

4 Comments

I can mass disable them, thanks. It did create some ugly border around it, messing with my format, though. Any tips?
@user2537383 You can hide it using the CSS I have added in my question. If it has helped you please upvote, and mark as answer. Thanks
I definitely will mark yours. Thanks for all the help. Just one last thing (hopefully). How can I have the boxes enable by default rather than disabled?
You're welcome. Just remove disabled="disabled" from the fieldset.
1

You're looking for the disabled property (not disable). Also, no need to escape your quotes

document.getElementById('freq2').disable=true;

Working Demo

1 Comment

Sorry, that it was I have. It is not working. Will edit above. Any other tips?
0

Try one of theese:

document.getElementById(\'freq2\').setAttribute('disabled', 'disabled');

Or

document.getElementById(\'freq2\').setAttribute('disabled', true);

Sample: http://jsfiddle.net/javitube/wzzHC/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.