Forum Moderators: open

Message Too Old, No Replies

Help coding a select input list where "other" allows a type in

         

jaeden

5:34 pm on Jan 15, 2003 (gmt 0)

10+ Year Member



I am trying to use one input field, and show a select list. If not in the list, then they should choose "other" and type in the real value. Is this possible? This doesn't seem to work.

<b>Type of Organization</b><IMG SRC="/images/Navigation/art/LittleR.gif"><br>
<select name="sarepcom">
<option value="Church">Church
<option value="Synagogue">Synagogue
<option value="School">School
<option value="Zoo">Zoo
<option value="Caterer">Caterer
<option value="Restaurant">Restaurant
<option value="Party Planner">Party Planner
<option value="Hotel Organization">Hotel Organization
<option value="Community Center">Community Center
<option value="Corporation">Corporation
<option value="">Other
</select><br><br>
If you chose Other, please specify<br>
<input type="Text" name="sarepcom" size="35" maxlength="80" VALUE=""></INPUT>

What do I need to do?

lorax

6:03 pm on Jan 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Well, for starters you can't have 2 fields of the same name and expect to get consistent results. The value of these fields will be passed regardless so the handler will get the value of the first field and then overwrite it with the value of the second field.

I'd change the name of the second field and use some script language to evaluate the form results. If the first field is set to 'other', then get the value of the 2nd field, otherwise ignore it.

Also, your code shows you're stuck halfway between an input field which doesn't have a closing tag and a textarea which does. Learn more here: [w3.org...]

jaeden

9:05 pm on Jan 15, 2003 (gmt 0)

10+ Year Member



Thanks, this is what I came up with.

function FillInCompType() {
document.addrform.sarepcom.value = document.addrform.comptype1.value
}


<b>Type of Organization</b><IMG SRC="/images/Navigation/art/LittleR.gif"><br>
<select name="comptype1" onChange="FillInCompType()">
<option value="" selected>Select one
<option value="Church">Church
<option value="Synagogue">Synagogue
<option value="School">School
<option value="Zoo">Zoo
<option value="Caterer">Caterer
<option value="Restaurant">Restaurant
<option value="Party Planner">Party Planner
<option value="Hotel Organization">Hotel Organization
<option value="Community Center">Community Center
<option value="Corporation">Corporation
</select><br>
Value chosen above, or enter another value if not listed.<br>
<input type="Text" name="sarepcom" size="35" maxlength="80" VALUE="">

It was too difficult to program the CGI program to handel two values when it expects only 1.

TheDave

3:44 am on Jan 16, 2003 (gmt 0)

10+ Year Member



That wouldnt work unless you have scripting on. You should really look at making it server side imo. I used to use quick fixes like this, but believe me, the extra time is worth spending. I only know asp but it would be something like:

myVar = request.form("valueA")
if myVar = "other" then myVar = request.form("valueB")

Surely its not hard to write something similar in cgi or whatever?

txbakers

5:10 am on Jan 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Dave's solution is very good, try to implement that.

You don't always have to use Request.Form("formElementName") in your scripts.

This type of processing can be very handy for lots of applications.