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
https://forums.phpfreaks.com/topic/96550-adding-input-boxes/#findComment-494276
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
https://forums.phpfreaks.com/topic/96550-adding-input-boxes/#findComment-494287
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.