Tuesday, 14 April 2020

Getting multiple checkboxes/checkbox group values in JSP.


In this post, we look that how can get the multiple checkbox/checkbox group values using JSP.

So first craete multiple checkboxes:-

<form id="" action="get_choice.jsp" method="post">

<input name='cid' type='checkbox' value='value1' />
<input name='cid' type='checkbox' value='value2' />
<input name='cid' type='checkbox' value='value3' />
<input name='cid' type='checkbox' value='value4' />

</form>

Now where we want to recieve these values (in my case it is get_choices.jsp)
In String array get these values-

String[] cid=request.getParameterValues("cid");

if(cid!=null)
{
for(int i=0;i<cid.length;i++)
{
out.print(cid[i]);
}
}

You can also store these values in different variables for further processing like-

String[] cid; String ch1,ch2,ch3;

cid=request.getParameterValues("cid");

if (cid != null)
{
for(int i=0;i<cid.length;i++)
{
if(i==0)
ch1=cid[0];
if(i==1)
ch2=cid[1];
if(i==2)
ch3=cid[2];

}
}




Change image source dynamically on hyperlink

 Changing image source dynamically using JQuery. Here in this example I have created there hyperlink and stored all images in the same folde...