Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Passing a variable from Javascript to java variable in a JSP.

843836Jun 9 2005 — edited Jun 9 2005
Here is simple test Ive been messing around with.

How do I assign the value that was selected in the radio button to a java variable in my JSP here. Javascript being client side and JSPs being serverside makes this difficult.
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">

function valbutton(thisform) 
{

	myOption = -1;
	for (i=0; i<thisform.myradiobutton.length; i++) 
	{
		if (thisform.myradiobutton.checked) 
{
myOption = i;
}
}

if (myOption == -1)
{
alert("You must select a radio button");
return false;
}

alert("You selected button number " + myOption + " which has a value of " + thisform.myradiobutton[myOption].value);
thisform.submit();

}

</SCRIPT>

<title>CreateCategoryContent</title>

</head>
<body>
<BR>


<center>




<%

for(int i = 0; i < 10; i++)
{

%>

<form name="myform">
<table border="1" bordercolor="#C0C0C0" width="50%" cellpadding="0" cellspacing="0" bgcolor="white">
<tr>
<td><%=i%><input type="radio" VALUE="<%=i%>" name="myradiobutton"></td>
</tr>

<%
}
%>

</form>
<input type="submit" name="submitit" onclick="valbutton(myform);return false;" value="Validate" />
</table>


</center>
<!--//T2-->
</body>
</html>


Thanks dudes.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 7 2005
Added on Jun 9 2005
10 comments
2,390 views