onchange event is not trigger when drop down size = 1

M

Matt

The following code won't work, because onchange event is not trigger
when drop down size = 1. But if I make the size="2" or greater, then
it will work. Is that true? please advise. thanks!!

<script type="text/javascript">
function showRange()
{ alert("showRange");
}
</script>
<SELECT NAME="range" SIZE="1" onchange="showRange();">
<OPTION VALUE="0">address 1</OPTION>
</SELECT>
 
M

McKirahan

Matt said:
The following code won't work, because onchange event is not trigger
when drop down size = 1. But if I make the size="2" or greater, then
it will work. Is that true? please advise. thanks!!

<script type="text/javascript">
function showRange()
{ alert("showRange");
}
</script>
<SELECT NAME="range" SIZE="1" onchange="showRange();">
<OPTION VALUE="0">address 1</OPTION>
</SELECT>

For "onChange()" to be detected one must move to a different <option>.

Often there is a blank <option> at the head of the list.
 
G

Grant Wagner

Matt said:
The following code won't work, because onchange event is not trigger
when drop down size = 1. But if I make the size="2" or greater, then
it will work. Is that true? please advise. thanks!!

<script type="text/javascript">
function showRange()
{ alert("showRange");
}
</script>
<SELECT NAME="range" SIZE="1" onchange="showRange();">
<OPTION VALUE="0">address 1</OPTION>
</SELECT>

It works fine if you have more than one <option>. If you only have a
single option, there is nothing to "change", so no "onchange" event can
be triggered. The reason it works if have a single <option> and you
specify size="2" is because you now have your defined <option> and an
empty, undefined space for an option. The user can now click that blank
entry, cause a "change" in the item selected which fires the onchange
event.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top