Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show/Hide Input type=text when SELECT=Other

Status
Not open for further replies.

NeoTurtle

Programmer
Aug 25, 2000
38
0
0
US
Hi everyone. Can anyone tell me how I can display an input textbox when someone selects Other from a select box?

Thanks in advance,
-Ivan
 
Yeah, I'd like to know how to do that too if it's possible. The trouble is that since the html is already loaded into the browser, you would have to reload the page before you could display more html. You could do that of course, passing all current values that the person has already entered into the new page. Seems kind of messy and user confusing though. You might consider popping up a prompt or a popup window to have them enter a value if they choose other. You can then assign the value of the prompt box/pop up window text box to a hidden input on the page. Not a real clean method either. Then there's the deal with the 'other' situation on the next page idea. Of course it may not fit into your scenario or application design. Even simpler, you could just give them a text box on that page that is disabled until they choose 'other'. Then when they choose 'other' the box can be enabled so they can enter their other value. Or you could use radio buttions instead and show a text box right next to the 'other' choice so they can enter it at that point.
All that talking and I haven't really answered the question! Good luck.

Thessa
 
In order to implement the show hide i have written a function which takes two arguments: the first one being the span id and the other being the name of the select box.
<html>
<head>

<style type=&quot;text/css&quot;>
.addons {position:relative;visibility:hidden}
</style>


<script language=&quot;JavaScript&quot;>
<!--
var Ver4 = parseInt(navigator.appVersion) >= 4
var Nav4 = ((navigator.appName == &quot;Netscape&quot;) && Ver4)
var IE4 = ((navigator.userAgent.indexOf(&quot;MSIE&quot;) != -1) && Ver4)


function flip(block,sel)
{
if (Nav4){
document.layers[block].visibility=(sel.options[sel.selectedIndex].value==&quot;Other&quot;) ? &quot;visible&quot; : &quot;hidden&quot;
}
else if(IE4)
{
document.all(block).style.visibility = (sel.options[sel.selectedIndex].value==&quot;Other&quot;) ? &quot;visible&quot; : &quot;hidden&quot;
}
}

//-->
</script>

</head>
<body>
<p>
<select onChange=&quot;flip('reasonBlock',this);&quot;>
<option selected value=&quot;Yes&quot;>Yes</option>
<option value=&quot;No&quot;>No</option>
<option value=&quot;Other&quot;>Other</option>
</select>

<span ID=&quot;reasonBlock&quot; class=&quot;addons&quot;>
<input name=&quot;someName&quot;>
</span>
</p>
</body>
</html>

;-)
 
hi!
no'p! this way is not so clear & soft (but i dont know the other way; may be someone else?):
layers in netscrap have their own different document object, so, u wuld have to neste form tags (in every layer (span) u shuld have <form>...</form>) - that means new problems with sendin data 2 server (as i know, only one form might be submited), so, u have 2 create another hidden form in wich u wuld copy all needed values from those forms that are in layers and than submit this one... wooof! looks like i told it
 
Sorry for the late &quot;Thanks a lot!!!&quot; . . . I got busy with other parts for the site design. :)
 
Ok . . . I've been trying to fix this for too long. It works great with just one item like that, but not with 2. I need one for State and Country. I can't seem to get it to work with Country. These are the changes I made for Country:
<select onChange=&quot;flip('reasonBlock',this);&quot;>
<select onChange=&quot;flip('reasonBlock2',this);&quot;>

<span ID=&quot;reasonBlock&quot; class=&quot;addons&quot;>
<span ID=&quot;reasonBlock2&quot; class=&quot;addons&quot;>

Any suggenstions??

Thanks in advance,
-Ivan
 
I got it by creating 2 functions. :)
<select onChange=&quot;flip('reasonBlock',this);&quot;>
<select onChange=&quot;flip2('reasonBlock2',this);&quot;>

<span ID=&quot;reasonBlock&quot; class=&quot;addons&quot;>
<span ID=&quot;reasonBlock2&quot; class=&quot;addons&quot;>
 
The above code doesn't seem to work in Netscape. It hides/shows an image or a text, but not a textbox/button. This happens only in Netscape.

Any idea why its happening?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top