Can javascript do this in jsp

Hello

Supose that in a form I have one select box. Using Javascript, I can know what option is selected. So in the form I have this

<form name="test">

<select name="test1" onChange="alertselected()">

<option>Option 1</option>

<option>Option 2</option>

</select>

</form>

And the JavaScript is:

function alertselected(){

alert(document.test.test1.selectedIndex)

However, if I have a dynamic list of select boxes. How I can know what option of a selectbox is selected. For example, I have:

<form name="test">

<select name="test1" onChange="alertselected()">

<option>Option 1</option>

<option>Option 2</option>

</select>

<select name="test2" onChange="alertselected()">

<option>Option 1</option>

<option>Option 2</option>

</select>

</form>

thank you

shoa

[1028 byte] By [sonhoanga] at [2007-10-3 5:35:56]
# 1

<form name="test">

<select name="test1" onChange="alertselected('test1')">

<option value"Option 1">Option 1</option>

<option value"Option 2">Option 2</option>

</select>

<select name="test2" onChange="alertselected('test2')">

<option value"Option 3">Option 3</option>

<option value"Option 4">Option 4</option>

</select>

</form>

<script language="javascript">

function alertselected(param)

{

var ind = eval("document.forms[0]."+param+".selectedIndex");

alert(ind);

}

</script>

Cheers

-Rohit

RohitKumara at 2007-7-14 23:43:33 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Thanks for your help

It can be seen that, in my example, I have two selectbox so it is easy to have alertselected('test1')" and alertselected('test2"). However, if I have a dynamic list of selectboxes (that means I donot know the size), how I can assign variable for the function alertselected

Thanks

sonhoanga at 2007-7-14 23:43:33 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

> Thanks for your help

>

> It can be seen that, in my example, I have two

> selectbox so it is easy to have

> alertselected('test1')" and alertselected('test2").

> However, if I have a dynamic list of selectboxes

> (that means I donot know the size), how I can assign

> variable for the function alertselected

>

> Thanks

I wish that you could visualize that you could dynamically generate this select box name and well as parameter to be passed in the javascript.

You can build all the select options in a for loop and assign the name to select box based on each count of the loop.

<select name="test<%=i%>" onChange=alertselected('test<%=i%>')">

-Rohit

RohitKumara at 2007-7-14 23:43:33 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...