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!

dropdown problem

Status
Not open for further replies.

nagusatya

Programmer
Jun 3, 2005
9
0
0
GB
hi all,

i am using the following code in my jsp as below in a <td>


<td>
<html:select property="payment" tabindex="1040"
styleId="withDrawalType" onchange="doIt(this);">
<option value="">Please Select</option>
<logic:iterate id="paymentValue" name="<%=WebConstants.getPaymentTypeListName()%>">
<option value="<bean:write name ="paymentValue"/>"><bean:write name="paymentValue" /></option>
</logic:iterate>

</html:select>
</td>

as you can see i am getting the collection from another file dynamically when my jsp is run on server.the above code works fine but the problem is
in my java script function i am changing the display as per the value in the dropdown list
normally i can give particular value is the drop down list code is like this:

<option value="Month">Month</option>

in this case i can use that

value='Month' in my java script function( single quotes in java script)

but how can i get the values if i am getting drop down list dynamically?

can you please suggest me the solution as i am halfway through?

regards and thanks in advance
 
Are you asking how to get the selected value in the drop down select object ?

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
yes mate i can have it if the code is like this:

<option value="Month">Month</option>
which is straight forward


but i am getting collection dynamically and how can i determine the value if each item in the dropdown list


cheers
 
Have a look at this :

Code:
<html>

<head>
	<script language="javascript">
		function doIt() {
			var selectObj = document.getElementById('mySelectBox');
			var selectIdx = selectObj.selectedIndex ;
			var selectValue = selectObj.options[selectIdx].value;
			alert(selectValue);
		}
	</script>
</head>

<body>
	<select id="mySelectBox">
		<option value="Month">Month</option>
		<option value="Day">Day</option>
		<option value="Year">Year</option>
	</select>

	<input type="button" onclick="doIt();" value="Click Me"/>
</body>

</html>

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
i dont know if this is exactly what your looking for but if you want to generate the drop down dynamically you would do it like this.

if the info is stored in an array, vector etc just create a loop and get the info accordingly.
Code:
<%
for( int i = 0; i < vecMonths.size(); i++ )
{
%>< option value = "<%= vecMonths.elementAt( i ).toString() %>" > <%= 
vecMonths.elementAt( i ).toString() %> </option>
<%}
%>

This will generate them dynamically but as regards getting the info into the java script, you may need to pass the values into a java script array as you add them to the option tag.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top