[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SELECT values



Hi, Andy,
   I like that you collect and create the exmaples for 411. It's good.
   Just a small note to your example on select: I think that it should
   include a test whether selectedIndex is set or not. It is always set in your
   example but when somebody uses multi-line selecttion, it may not be
   true. My suggestion is:

      function showSelected(form) {
       var selected = form.make.selectedIndex;
       form.display.value = (selected == -1 ? "" :
                             form.make.options[selected].text);
      }

Best regards,
Martin Senger

> 
> ********************
> <HTML><HEAD><TITLE>Guide to Select Object</TITLE>
> 
> <SCRIPT LANGUAGE="Javascript">
> <!-- 
> 
> function showSelected(form) {
>  form.display.value = form.make.options[form.make.selectedIndex].text
> 
> }
> // -->
> </SCRIPT></HEAD>
> 
> <BODY>
> <FORM NAME="test">
>  <SELECT NAME="make">
>   <OPTION>Ford 
>   <OPTION>Saturn
>   <OPTION>Yugo
>  </SELECT>
>  <INPUT TYPE="button" VALUE="Show selected option"
>    onClick="showSelected(this.form)">
>  <INPUT NAME="display">
> </FORM>
> </BODY></HTML>
> 
> -Andy Augustine
> JavaScript 411 -- http://www.freqgrafx.com/411/
> 


-- 
------------------------------------------------------
| Martin Senger     m.senger@dkfz-heidelberg.de      |
|                   voice: (0049) 6221/422340        |
|                   fax:   (0049) 6221/422333        |
------------------------------------------------------
--------------------------------------------------------------------
For help about the list, please send a message to 'majordomo@obscure.org'
with the message body 'help'. To unsubscribe, send a message to
'majordomo@obscure.org' with the message body 'unsubscribe javascript'.
List archives and pointer to FAQ: http://www.obscure.org/javascript/