|
-
Apr 22nd, 2002, 04:01 PM
#1
Thread Starter
Frenzied Member
JavaScript: Setting the disabled Flag
I'm trying to set the disabled flag on a input element. If you know of an easier way, please. Othwise, what is wrong with this?
Code:
<html>
<head>
<title>Test Page</title>
<script type="text/javascript">
function foo() {
alert(document.getElementByID("myInput").nodeName);
}
</script>
</head>
<body>
<form name="myForm">
<input id="myInput" type="text" size="8" value="2">
</form>
<p onclick="javascript:foo();">Click Me</p>
</body>
</html>
I can't get it to return nodeName, much less can I try to setAttributeNode, which may not even be what I need to do.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Apr 23rd, 2002, 04:36 AM
#2
Fanatic Member
Hi,
I changed D in ID to lowercase it I got it work in IE...
Code:
alert(document.getElementById("myInput").nodeName);
... whats the problem you are having?
I know it may be a stupid question but have you tried using style.disabled?
Code:
document.getElementById("myInput").style.disabled=true;
-
Apr 23rd, 2002, 08:43 AM
#3
Thread Starter
Frenzied Member
Oh forget it.
Code:
<html>
<head>
<title>Test Page</title>
<script type="text/javascript">
function enableBox() {
document.getElementById("myInput").disabled = false;
}
function disableBox() {
document.getElementById("myInput").disabled = true;
}
function foo() {
alert(document.getElementById("myInput").nodeName);
}
</script>
</head>
<body>
<form name="myForm">
<p>Disabled: <input type="text" size="8" disabled></p>
<p><input id="myInput" name="myInput" type="text" size="8" value="2"></p>
<p><input name="myRadio" type="radio" onclick="javascript:enableBox();">Enable</p>
<p><input name="myRadio" type="radio" onclick="javascript:disableBox();">Disable</p>
<p><input name="myButton" type="button" onclick="javascript:foo();" value="Click"></p>
</form>
</body>
</html>
.disabled works, though I don't find it in the documentation. I find .nodeName in the documentation, but it doesn't work in Opera. I'll get over it, that is Opera's fault.
.style.disabled I think is meant to disable the style attribute, not the element itself.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Apr 23rd, 2002, 08:52 AM
#4
Fanatic Member
.style.disabled I think is meant to disable the style attribute, not the element itself.
Whoops, I meant disabled on its own, i'm used to putting style if front because I work with CSS a lot.
I cant find any decent documentation on it disabled either, I just guessed it would be this as disabled is an attribute for the input tag.
-
Apr 23rd, 2002, 09:24 AM
#5
Thread Starter
Frenzied Member
Well, if it isn't documented as part of the standard, I don't want to use it. If it blows up in a browser, it is my fault.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
-
Apr 23rd, 2002, 09:32 AM
#6
Fanatic Member
I searched and I found it as part of the HTML4.01 standard at W3.org
http://www.w3.org/TR/html401/interac...#adef-disabled
It also does mention that you can dynamically change it using a script so I think you should be ok.
-
Apr 23rd, 2002, 09:37 AM
#7
Thread Starter
Frenzied Member
Yeah, I just don't know if I can say NodeObj.disabled, or if I'm supposed to say NodeObj.setAttribute("disabled") or something like that.
Travis, Kung Foo Journeyman
As always, RTFM.
WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
YBMS, but Mozilla doesn't.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|