html - Can I get two value in a select option tag, then call it in a servlet? -
here want 2 option value, project.id, , project.name
<select name="project" id="project"> <option value="0" selected>select project</option> <c:foreach var="project" items="${project}"> <option value="${project.id project.name}">${project.name}</option> </c:foreach> </select>
and in servlet, want this, possible?
int projectid = integer.parseint(request.getparameter("project")); int projectname = request.getparameter("project");
how do this?
you have write value in option using seperator. @ servlet end, use split function seperate values , use them. check answer : split string function.
or, can use javascript so, have take 2 other hidden inputs pass values. check script :
function splitvalue(){ var optval=document.getelementbyid("instno").value; var valarray=optval.split(','); for(var i=0;i<valarray.length;i++){ document.getelementbyid("number").value=valarray[0]; document.getelementbyid("text").value=valarray[1]; } }
<select id="instno" name="instno" onchange="splitvalue();"> <option value="1,abc">abc</option> <option value="2,xyz">xyz</option> </select> <input type="text" id="number" name="number"/> <input type="text" id="text" name="text"/>
here in place of input text, can use input type="hidden" hide inputs. , pass these servlet instead of select option values.
Comments
Post a Comment