/    Sign up×
Community /Pin to ProfileBookmark

Disabling parts of form

Hi

i wonder if anyone can help solve this problem. I am guessing that it will probably be
a simple and silly oversight on my part, but being new to JavaScript I am not quite
sure where I am going wrong.

Problem:

using a checkbox I wish to disable or enable certain part of a form. The parts in question
being a button and a text field.

Below I have included a sample snippet of the code that i have used without any success:

function disable(){
if(document.test.testBox.checked==true){
var button = document.getElementByTagName(“input”);
button[2].value = “please wait”;
button[2].disabled = “true”;
}else{
button[2].disabled = “false”;
}//end

function disableTwo(){
var button = document.getElementById(“testButton”).value;
button.disabled = “false”;
}//end
</script>
</head>
<input type = “checkBox” id = “testBox” name = “testBox” value=”test” onClick = “disable();”> Test

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@crh3675Apr 13.2004 — the disabled values are boolean, not text:

<i>
</i>function disable(){
if(document.test.testBox.checked==true){
var button = document.getElementByTagName("input");
button[2].value = "please wait";
button[2].disabled =true
}else{
button[2].disabled =false
}//end


Also, I would be referencing each object by ID and not by TAGNAME. An <input type="checkbox" is different from an <input type="button"
×

Success!

Help @EdJaye spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...