Theiling Online    Sitemap    Conlang Mailing List HQ    Attic   

Re: OT: TECH: JavaScript help

From:Mark J. Reed <markjreed@...>
Date:Monday, December 22, 2008, 19:27
On Mon, Dec 22, 2008 at 2:01 PM, Gary Shannon <fiziwig@...> wrote:
> <form name="my_form" action="test.html"> > <input type="text" name="foo" value="tee"> > <select name="bar" > onclick="document.my_form.foo.value=document.my_form.bar.options[document.my_form.bar.selectedIndex].value"> > <option value="tee" selected="selected">tee</option> > <option value="tie">tie</option> > <option value="toe">toe</option> > </select> > </form>
I'm still not clear on the purpose here. That will display the "value" of the option inside the text input, sure. Is that what Benct was asking for? Usually you have options that have "internal" names designed for software consumption (the value) and then more descriptive labels for presentation to humans (the contents of the option element). If you want to display a more verbose description or something, it's not clear that the value is the appropriate place to store it... If you go with the above, I can suggest a couple minor improvements: 1. onchange is a better handler for this than onclick. No sense doing anything if the user clicks on the drop-down without changing anything. 2. When the on* handler is invoked, the input object - in this case, the select element - is the invocant. So you can use "this" instead of "document.my_form.bar" and get code that is both more compact and easier to adapt to differently-named inputs. -- Mark J. Reed <markjreed@...>

Reply

Gary Shannon <fiziwig@...>