Jump to content

Adding Input Boxes


ann86

Recommended Posts

If you put it in the select tag then it would display the box no matter what option was selected. The way I understood it, he was trying to have the input be shown only when a specific option was selected. Athough, to toggle the visibility off, you would need an if statement unless you put an onreadystatechange event in every option (don't), so you might as well put it in the select using onchange and do some checking.

<select id="sel" onchange="if(sel.options(sel.selectedIndex).name='other'){box.style.visibility='visible'}else{box.style.visibility='hidden'">
<option name="other" value="something">Other</option>
</select>
<input type=text id="box" style="visibility:hidden">

 

Something like that. I don't think javascript in the tags works in some cases, but I hope you get the idea.

Link to comment
Share on other sites

sample code

<html>
<head>
<meta name="generator" content="PhpED Version 4.5 (Build 4513)">
<title>sample</title>
<meta name="author" content="Barand">
<meta name="creation-date" content="03/17/2008">
<script language='javascript'>
         function choiceChanged (sel)
         {
             var txtObj = document.getElementById("other");
             if (sel.options[sel.selectedIndex].value=="0")
             {
                 txtObj.style.visibility="visible";
             }
             else {
                 txtObj.style.visibility="hidden";
             }
         }
</script>
</head>
<body>
    <form>
        <select name='choice' onchange='choiceChanged(this)'>
            <option value='1'> aaa</option>
            <option value='2'> bbb</option>
            <option value='3'> ccc</option>
            <option value='0'> other</option>
        </select>
        <div id="other" style='visibility: hidden'>
                Specify 'other' <input type="text" name="choice1" size="20">
        </div>
        <input type="submit" name="sub" value="Submit">
    </form>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.