Make textbox appear onMouseClick in drop-down menu option?

A

AES

Currently, I am working on developing a form in
FrontPage. I would like to incorporate a drop-down list
including "Other" as an option, where if "Other" is
selected (or clicked), a text box for fill-in response
will appear.
Is this possible? And, if so, how?
Any help will be greatly appreciated! Thanks!
 
J

Jim Buyens

-----Original Message-----
Currently, I am working on developing a form in
FrontPage. I would like to incorporate a drop-down list
including "Other" as an option, where if "Other" is
selected (or clicked), a text box for fill-in response
will appear.
Is this possible? And, if so, how?
Any help will be greatly appreciated! Thanks!

Here's a sample page that does what you want. Create a new
blank page, switch to code view, delete everything, then
copy and paste from here.

<html>
<head>
<title>Ratings Form</title>
<script>
function ckIfOther(){
if (document.forms[0].ddlRating.selectedIndex ==
document.forms[0].ddlRating.options.length - 1){
if (document.getElementById) {
document.getElementById
("txtOther").style.visibility="visible";
return;
}
if (document.all) {
document.all["txtOther"].style.visibility="visible";
return;
}
if (document.layers) {
document.layers["txtOther"].visibility="show";
}
}else{
if (document.getElementById) {
document.getElementById
("txtOther").style.visibility="hidden";
return;
}
if (document.all) {
document.all["txtOther"].style.visibility="hidden";
return;
}
if (document.layers) {
document.layers["txtOther"].visibility="hide";
}
}
}
</script>
</head>

<body>

<form method="POST">
<table border="0" cellpadding="2" cellspacing="0">
<tr>
<td><select size="1" name="ddlRating"
onchange="ckIfOther();">
<option>Good</option>
<option>Bad</option>
<option>Worse</option>
<option>(other)</option>
</select></td>
<td><input type="text" name="txtOther" size="20"
style="visibility: hidden;"></td>
</tr>
</table>
<p><input type="submit" value="Submit" name="btnSub"></p>
</form>
</body>
</html>

Jim Buyens
Microsoft FrontPage MVP
http://www.interlacken.com
Author of:
*----------------------------------------------------
|\---------------------------------------------------
|| Microsoft Office FrontPage 2003 Inside Out
||---------------------------------------------------
|| Web Database Development Step by Step .NET Edition
|| Microsoft FrontPage Version 2002 Inside Out
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/---------------------------------------------------
*----------------------------------------------------
 
J

Jon Spivey

There's a couple of issues I can see here
1/ Trying to support NN4 with document.layers won't work - NN4 will only
allow you to change visibility of an absolutely positioned div.
2/ You'd want to use display rather than visibility so the text box doesnt
leave blank space on the page when its hidden
3/ You'd also want to hide the text box when the user chooses other and then
changes his mind
I'd do this

<script type="text/javascript">
function changeForm(f){
if(!document.getElementById)return;
document.getElementById('other').style.display=(f.options.selectedIndex==f.o
ptions.length-1)?'block':'none';
}
</script>

<select onchange="changeForm(this);">
<option value="something">something</option>
<option value="somethingelse">something else</option>
<option value="">other</option>
</select>
<div id="other" style="display:none">
type your other stuff here
<input type="text" name="whatever">
</div>

--
Cheers,
Jon
Microsoft MVP




<select onchange="if(document.getElementById &&
this.options.selectedIndex==this.options.length-1)
Jim Buyens said:
-----Original Message-----
Currently, I am working on developing a form in
FrontPage. I would like to incorporate a drop-down list
including "Other" as an option, where if "Other" is
selected (or clicked), a text box for fill-in response
will appear.
Is this possible? And, if so, how?
Any help will be greatly appreciated! Thanks!

Here's a sample page that does what you want. Create a new
blank page, switch to code view, delete everything, then
copy and paste from here.

<html>
<head>
<title>Ratings Form</title>
<script>
function ckIfOther(){
if (document.forms[0].ddlRating.selectedIndex ==
document.forms[0].ddlRating.options.length - 1){
if (document.getElementById) {
document.getElementById
("txtOther").style.visibility="visible";
return;
}
if (document.all) {
document.all["txtOther"].style.visibility="visible";
return;
}
if (document.layers) {
document.layers["txtOther"].visibility="show";
}
}else{
if (document.getElementById) {
document.getElementById
("txtOther").style.visibility="hidden";
return;
}
if (document.all) {
document.all["txtOther"].style.visibility="hidden";
return;
}
if (document.layers) {
document.layers["txtOther"].visibility="hide";
}
}
}
</script>
</head>

<body>

<form method="POST">
<table border="0" cellpadding="2" cellspacing="0">
<tr>
<td><select size="1" name="ddlRating"
onchange="ckIfOther();">
<option>Good</option>
<option>Bad</option>
<option>Worse</option>
<option>(other)</option>
</select></td>
<td><input type="text" name="txtOther" size="20"
style="visibility: hidden;"></td>
</tr>
</table>
<p><input type="submit" value="Submit" name="btnSub"></p>
</form>
</body>
</html>

Jim Buyens
Microsoft FrontPage MVP
http://www.interlacken.com
Author of:
*----------------------------------------------------
|\---------------------------------------------------
|| Microsoft Office FrontPage 2003 Inside Out
||---------------------------------------------------
|| Web Database Development Step by Step .NET Edition
|| Microsoft FrontPage Version 2002 Inside Out
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/---------------------------------------------------
*----------------------------------------------------
 
T

Tom Pepper Willett

J

Jim Cheshire

Tom said:
Jim who? Thanks for what? What looks great? What thread is this
supposed to be in? ;-)

I assumed they were talking to me because I had just spent all afternoon
grooming my lawn. Was I wrong?

--
Jim Cheshire
JIMCO
http://www.jimcoaddins.com
Free add-ins for FrontPage

Author of Special Edition
Using Microsoft Office FrontPage 2003
 
K

Kevin Spencer

Well, Jim, I'm sure you deserved it. At least from one or 2 people. ;-)!

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Top