www.webdeveloper.com
Results 1 to 6 of 6

Thread: extra textbox in form

  1. #1
    Join Date
    Dec 2004
    Location
    The Netherlands
    Posts
    97

    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>
    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é

  2. #2
    Join Date
    Jan 2005
    Location
    Los Angeles, CA
    Posts
    4,887
    I'm no good with Compatibility, but this works with IE.

    Code:
    <script>
    var AndersCheckBox="<br>Some other option<input type=\"checkbox\">";
    function Anders_Check(){
    if(arguments[0]=="anders:"){AndersExtension.innerHTML=AndersCheckBox}
    else{AndersExtension.innerHTML=""}
    }
    </script>
    <select name="dropdown" size="1" onchange="Anders_Check(this.value)">
    <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>
    <Div ID="AndersExtension"></Div>

  3. #3
    Join Date
    Dec 2004
    Location
    KS
    Posts
    147
    Originally posted by Ultimater
    I'm no good with Compatibility, but this works with IE.
    didnt work in FF, try this...

    Code:
    <script>
    var AndersTxt="<br>More Text<input type=\"text\">";
    function Anders_Check(sel){
    if (sel=="anders:"){
    document.getElementById("AndersExtension").innerHTML = AndersTxt;
    }else{
    document.getElementById("AndersExtension").innerHTML = "";
    }
    }
    </script>
    <select name="dropdown" size="1" onchange="Anders_Check(this.value)" onkeyup="Anders_Check(this.value)">
    <option value="Een vraag">Een vraag</option>
    <option value="Een suggestie">Een suggestie</option>
    <option value="Commentaar of feedback" selected>Commentaar of feedback</option>
    <option value="anders:">Anders, namelijk:</option>
    </select>
    <Div ID="AndersExtension"></Div>
    onchange AND onkeyup cause FF didnt seem to respond to me using the down arrow through the select box...

  4. #4
    Join Date
    Dec 2004
    Location
    The Netherlands
    Posts
    97
    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...

    Regards,

    René

    P.s.: Also trying to enable the box when the option is chosen... Won't work yet :P

  5. #5
    Join Date
    Dec 2004
    Location
    KS
    Posts
    147
    Originally posted by renevanh

    Can I edit this text? I can't find it in your code...:rolleyes:
    Code:
    <script>
    var AndersTxt="<br>More Text<input type=\"text\">";
    function Anders_Check(sel){
    if (sel=="anders:"){
    document.getElementById("AndersExtension").innerHTML = AndersTxt;
    }else{
    document.getElementById("AndersExtension").innerHTML = "";
    }
    }
    </script>
    <select name="dropdown" size="1" onchange="Anders_Check(this.value)" onkeyup="Anders_Check(this.value)">
    <option value="Een vraag">Een vraag</option>
    <option value="Een suggestie">Een suggestie</option>
    <option value="Commentaar of feedback" selected>Commentaar of feedback</option>
    <option value="anders:">Anders, namelijk:</option>
    </select>
    <Div ID="AndersExtension"></Div>
    P.s.: Also trying to enable the box when the option is chosen... Won't work yet :P
    Not sure what you mean here...

  6. #6
    Join Date
    Dec 2004
    Location
    The Netherlands
    Posts
    97
    Not sure what you mean here...
    Don't bother about it... got the form working

    Thanks alot!

    Regards,

    René

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles