Skip to Main Content

Oracle Forms

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!

Get multiple textbox value in CheckBox values attribute in jsp and fetch the checkbox value in servl

S.K.SahaAug 11 2013 — edited Aug 13 2013

Hi,

i have written this in jsp

---------------------------------------------

<%@page import="com.sun.org.apache.xerces.internal.impl.xs.identity.ValueStore"%>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

    pageEncoding="ISO-8859-1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Insert title here</title>

<script type="text/javascript">

function getvalue(){

  var elems = document.getElementsByTagName('input');

  var values = [];

  for(var i=0; i< elems.length; i++){

  if (elems[i].type == "text"){

  values.push(elems[i].value);

  }

  }

  for(var i=0; i< values.length; i++){

  alert(values[i]);

  }

  request.setAttribute("res",values);

}

</script>

</head>

<body>

<form action="checkbox">

<table>

<tr>

<td>First Name:<input type="text" name="first"  id="text1"/></td>

<td>Second Name:<input type="text" name="second"  id="text2"/></td>

<td>check both<input type="checkbox" id="chk" name="allValue" value="<%=request.getAttribute("res")%>" onclick="getvalue()"/>

</td>

</tr>

<tr><td><input type="submit" value="OK" ></td>

</tr>

</table>

</form>

</body>

</html>

And Servlet Code

--------------------------

package com.test;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public class TestServlet extends HttpServlet {

  protected void service(HttpServletRequest req,HttpServletResponse res)

  {

  String[] str=req.getParameterValues("allValue");

  for(int i=0;i<str.length;i++)

  {

  System.out.println("checkbox:"+str[i]);

  }

  }

}

----------------------------------

here i am getting null value in servlet even though i have set the all textbox values in request in javascript function as i have written in above code

please suggest me if any solution is there

Thanks,

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 10 2013
Added on Aug 11 2013
1 comment
1,230 views