Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #14043

Re: FAQ Topic - How do I get the value of a form control? (2012-05-20)

Newsgroups comp.lang.javascript
Subject Re: FAQ Topic - How do I get the value of a form control? (2012-05-20)
From "Evertjan." <exjxw.hannivoort@interxnl.net>
References <4fb825fb$0$292$14726298@news.sunsite.dk>
Message-ID <XnsA059686CC37FBeejj99@194.109.133.133> (permalink)
Date 2012-05-20 08:15 +0000

Show all headers | View raw


FAQ server wrote on 20 mei 2012 in comp.lang.javascript:

> var value = control.value;
> value = +control.value; //string to number.
> 
> Some exceptions would be:
> 
> First Exception: Where the control is a `SELECT` element, and
> support for older browsers, such as NN4, is required:
> 
> var value = control.options[control.selectedIndex].value;

This is nice, I don't support NN4.

However you cannot write to this select value,
so you still need selectedIndex for setting the option:

Example:

============================
<select onchange='
document.getElementById("s").innerHTML=this.value;
this.selectedIndex=0;
'>
<option>--</option>
<option value=a>a</option>
<option value=b>b</option>
<option value=c>c</option>
<option value=d>d</option>
</select>
<span id=s>--</span>
============================


btw, it seems that IE9 still does not support the defaulting:

<option>a</option>

but needs:

<option value=a>a</option>


-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

FAQ Topic - How do I get the value of a form control? (2012-05-20) "FAQ server" <javascript@dotinternet.be> - 2012-05-19 23:00 +0000
  Re: FAQ Topic - How do I get the value of a form control? (2012-05-20) "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-05-20 08:15 +0000

csiph-web