Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does onclick of an <option> tag inside a <select> tag work?

Status
Not open for further replies.

salils

Programmer
Mar 11, 2002
12
0
0
US
Hello friends,
I am trying to call a function from the onclick of an <option> tag. I just have a simple alert message within the function. The function doesn't get called. I have posted the code below:

<HEAD>
<SCRIPT type="text/javascript">
function func_1() {
alert('test');
}</SCRIPT>
</HEAD>
<body>
<SELECT size="10" name="Reports">
<OPTION value="unapproved">Unapproved</OPTION>
<OPTION value="history" onclick="func_1();">History</OPTION>
</SELECT>
</body>

Thanks,
Salil
 
salils, the onclick does not work for the option tag but you can do something like this.
Code:
<HEAD>
<SCRIPT type="text/javascript">
function func_1(which) {
  alert(which);
}
</SCRIPT>
</HEAD>
<body>
<SELECT size="10" name="Reports"  onclick="func_1(this.options[this.selectedIndex].value);">
<OPTION value="unapproved">Unapproved</OPTION>
<OPTION value="history">History</OPTION>
</SELECT>
</body>

When a change is made to the selection it passes the value of the newly selected item to the function. You should be able to do what you need that way.


Stamp out, eliminate and abolish redundancy!
 
yep. I did something similar and it has worked.

Thanks,
Salil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top