/    Sign up×
Community /Pin to ProfileBookmark

extra textbox in form

Hey all,

I’m building a form for my site, but now I want to get an extra textbox when an option in a dropdownbox is selected.

I did some search, and I found something about “onChange” and innerHTML, but I can’t figure it out…

This is the dropdown:

[code]
<select name=”dropdown” size=”1″>
<option value=”Een vraag”>Een vraag
<option value=”Een suggestie”>Een suggestie
<option value=”Commentaar of feedback” selected>Commentaar of feedback
<option value=”anders:”>Anders, namelijk:
</select>
[/code]

Now, when someone selects the option “Anders, namelijk”(means else: ), I want an extra textbox to appear.

Can someone give me a good example, so I will understand?

In andvanced thanks,

René

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterFeb 11.2005 — I'm no good with Compatibility, but this works with IE.

<i>
</i>&lt;script&gt;
var AndersCheckBox="&lt;br&gt;Some other option&lt;input type="checkbox"&gt;";
function Anders_Check(){
if(arguments[0]=="anders:"){AndersExtension.innerHTML=AndersCheckBox}
else{AndersExtension.innerHTML=""}
}
&lt;/script&gt;
&lt;select name="dropdown" size="1" onchange="Anders_Check(this.value)"&gt;
&lt;option value="Een vraag"&gt;Een vraag
&lt;option value="Een suggestie"&gt;Een suggestie
&lt;option value="Commentaar of feedback" selected&gt;Commentaar of feedback
&lt;option value="anders:"&gt;Anders, namelijk:
&lt;/select&gt;
&lt;Div ID="AndersExtension"&gt;&lt;/Div&gt;
Copy linkTweet thisAlerts:
@johneboyFeb 11.2005 — [i]Originally posted by Ultimater [/i]

[B]I'm no good with Compatibility, but this works with IE.

[/b]

[/QUOTE]

didnt work in FF, try this...

<i>
</i>&lt;script&gt;
var AndersTxt="&lt;br&gt;More Text&lt;input type="text"&gt;";
function Anders_Check(sel){
if (sel=="anders:"){
document.getElementById("AndersExtension").innerHTML = AndersTxt;
}else{
document.getElementById("AndersExtension").innerHTML = "";
}
}
&lt;/script&gt;
&lt;select name="dropdown" size="1" onchange="Anders_Check(this.value)" onkeyup="Anders_Check(this.value)"&gt;
&lt;option value="Een vraag"&gt;Een vraag&lt;/option&gt;
&lt;option value="Een suggestie"&gt;Een suggestie&lt;/option&gt;
&lt;option value="Commentaar of feedback" selected&gt;Commentaar of feedback&lt;/option&gt;
&lt;option value="anders:"&gt;Anders, namelijk:&lt;/option&gt;
&lt;/select&gt;
&lt;Div ID="AndersExtension"&gt;&lt;/Div&gt;


onchange [b]AND[/b] onkeyup cause FF didnt seem to respond to me using the down arrow through the select box...
Copy linkTweet thisAlerts:
@renevanhauthorFeb 14.2005 — Thanks johneboy, it works perfectly.

Just another question...

When I select the "anders, namelijk:" option, I get the text "More text:" and then the box.

Can I edit this text? I can't find it in your code...:rolleyes:

Regards,

René

P.s.: Also trying to enable the box when the option is chosen... Won't work yet ?
Copy linkTweet thisAlerts:
@johneboyFeb 14.2005 — [i]Originally posted by renevanh [/i]

[B]

Can I edit this text? I can't find it in your code...:rolleyes:

[/B]
[/QUOTE]

<i>
</i>&lt;script&gt;
var AndersTxt="&lt;br&gt;[b]More Text[/b]&lt;input type="text"&gt;";
[COLOR=silver]function Anders_Check(sel){
if (sel=="anders:"){
document.getElementById("AndersExtension").innerHTML = AndersTxt;
}else{
document.getElementById("AndersExtension").innerHTML = "";
}
}
&lt;/script&gt;
&lt;select name="dropdown" size="1" onchange="Anders_Check(this.value)" onkeyup="Anders_Check(this.value)"&gt;
&lt;option value="Een vraag"&gt;Een vraag&lt;/option&gt;
&lt;option value="Een suggestie"&gt;Een suggestie&lt;/option&gt;
&lt;option value="Commentaar of feedback" selected&gt;Commentaar of feedback&lt;/option&gt;
&lt;option value="anders:"&gt;Anders, namelijk:&lt;/option&gt;
&lt;/select&gt;
&lt;Div ID="AndersExtension"&gt;&lt;/Div&gt;[/COLOR]


[B]P.s.: Also trying to enable the box when the option is chosen... Won't work yet ? [/B][/QUOTE]

Not sure what you mean here...
Copy linkTweet thisAlerts:
@renevanhauthorFeb 16.2005 — 
Not sure what you mean here...
[/quote]


Don't bother about it... got the form working

Thanks alot!

Regards,

René
×

Success!

Help @renevanh 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.17,
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,
)...