Forum Moderators: open

Message Too Old, No Replies

Select list with "other" option

choose "other" and user could custom input another item

         

neophyte

9:29 am on Sep 8, 2004 (gmt 0)

10+ Year Member



Got a client who wants a "semi-static" select list of author names.

BUT, he also wants an item in the select list to say "Other"...no big deal...so far.

If a user chooses the "other" item, the select list would then "turn into" (his words) an editable text field of sorts which the user could then use to input a non-listed name.

Anybody know how to do this? Or something simular? It seems like I've seen this before, but not very often.

All help greatly appreciated.

Neophyte

Span

9:41 am on Sep 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looks like you need a site search engine..

R1chard

11:02 am on Sep 8, 2004 (gmt 0)

10+ Year Member



If only Comboboxes were part of html...

As it is, I've seen several home-made solutions. I guess the simplest is to have a neighboring textbox which is hidden by CSS. When they select "Other", you have a function that makes it visible (and maybe gives focus).

TheDoctor

11:21 am on Sep 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could write a Java applet ;)

StupidScript

7:41 pm on Sep 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<script type="text/javascript" language="javascript">
function chkOther(fld,len,idx) {
if ((idx+1)==len) {
other=prompt("Please indicate 'Other' value:");
fld.options[idx].value=other;
fld.options[idx].text=other;
}
}
</script>
<form name="selectform">
Choose: <select name="choices" onchange="chkOther(this,this.options.length,this.options.selectedIndex)">
<option value="Home" />Home
<option value="Work" />Work
<option value="" />Other
</select>
</form>

Instead of using a prompt(), you could pop up another small form in a window and send the new value to the parent window, if XPSP2 lets you. :)

neophyte

11:48 pm on Sep 8, 2004 (gmt 0)

10+ Year Member



Thanks to all who replied to this thread. I'll try StupidScript's solution to see if that fits the bill.

Neophyte

dcrombie

2:06 pm on Sep 9, 2004 (gmt 0)



We get clients requesting this every now and then. They seem to think the web is the same as Access. If you can explain that it's not then you make life a lot easier.

Otherwise:

The reason you'd use a SELECT box is to _restrict_ user input.
The reason they want 'other' is that they've come up with something to enter that's not in the list.

So, my solution is to place a SELECT box (nameless) above a (named) INPUT box.
When a value's selected (onChange), copy it into the INPUT box.
Or they can type what they want. Problem solved!

The beauty of this, if you're using a database, is that you can populate the SELECT box using "SELECT DISTINCT(value) FROM table". I can almost guarantee that after a few weeks or months they'll come back to you asking for the 'Other' option to be taken out because they can see for themselves how much crap has been entered ;)

StupidScript

6:28 pm on Sep 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



dcrombie, excellent solution! Quite neat.

neophyte

8:50 am on Sep 10, 2004 (gmt 0)

10+ Year Member



dcrombie - yes, this is a nice and handy option. I'll show that to them. Thanks for the reply.