kondakindi
IS-IT--Management
Hi,
I have a select box in the jsp page i would like to check if the user has selected any item if not it should not proceeed and reload the same page with error stating you have to select .
i have wriiten a function to check null values it doesn't work..
<select name="q_value">
<option value="q_val" " <%= isMultipleSelected(request, "q_value" , q_val)%> ">One
</select>
funtion is :
<%! public static String[] getFormElementValues(HttpServletRequest request, String formElementName)
{
String [] values = null;
if (!((request ==null) || (formElementName ==null)||(request.getParameter(formElementName) ==null)))
{
values = (String[])request.getParameterValues(formElementName);
}
return values;
}
public static String isMultipleSelected (HttpServletRequest request, String param, String testValue)
{
if (getFormElementValues(request, param) != null )
{
String[] values = getFormElementValues(request, param);
for(int i =0;i<values.length;i++)
{
String Value = (String)values;
if(Value.equals(testValue))
return " selected ";
}
}
return "";
}
%>
Do let me know is it right...
Thanks,
I have a select box in the jsp page i would like to check if the user has selected any item if not it should not proceeed and reload the same page with error stating you have to select .
i have wriiten a function to check null values it doesn't work..
<select name="q_value">
<option value="q_val" " <%= isMultipleSelected(request, "q_value" , q_val)%> ">One
</select>
funtion is :
<%! public static String[] getFormElementValues(HttpServletRequest request, String formElementName)
{
String [] values = null;
if (!((request ==null) || (formElementName ==null)||(request.getParameter(formElementName) ==null)))
{
values = (String[])request.getParameterValues(formElementName);
}
return values;
}
public static String isMultipleSelected (HttpServletRequest request, String param, String testValue)
{
if (getFormElementValues(request, param) != null )
{
String[] values = getFormElementValues(request, param);
for(int i =0;i<values.length;i++)
{
String Value = (String)values;
if(Value.equals(testValue))
return " selected ";
}
}
return "";
}
%>
Do let me know is it right...
Thanks,