• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1346
  • Last Modified:

when i click the checkbox only the value should come to servlet

i will display the  values from the DB with the checkboxes by default it will be checked.
when i click the checkbox only the value should come to servlet;


i put hidden parameter like this;in the servlet if i write request.getParameterValues("checkHouse") all the values are coming;but my requirment is when i check the checkbox only the value should come to servlet;how to write javascript function for this?

<input type="hidden" name="checkHouse" value=1111>
<input type="hidden" name="checkHouse" value=12>
<input type="hidden" name="checkHouse" value=11331>
<input type="hidden" name="checkHouse" value=114411>
0
chaitu chaitu
Asked:
chaitu chaitu
1 Solution
 
fargoCommented:
how many checkboxes are u displaying in the page?  and moreover, if u name all of them the same..u will get all the values anyway. What are u trying to achieve? Do u have a list of data and u wish to select /de select them? Use indexed properties from Struts.
0
 
actonwangCommented:
>>but my requirment is when i check the checkbox only the value should come to servlet;how to write javascript function for this?

You can achieve this by simple js function. See the following reference code:

<script>

     function toggleHiddens()
      {
            
             var _form = document.forms['MyForm'];
            
             var cb = _form.elements['test1'];
            
             for(var i=0;i<_form.length;i++)
             {
                if(_form.elements[i].name == 'checkHouse')
                {
                       _form.elements[i].disabled = !cb.checked;
                }       
             }
            
            
             return true;
      }
</script>
 <form name="MyForm" action="test.html" method="get">

<input type="checkbox" name="toggle" value="soso" checked onclick="toggleHiddens();"/>    
<input type="hidden" name="checkHouse" value=12>
<input type="hidden" name="checkHouse" value=11331>
<input type="hidden" name="checkHouse" value=114411>

</form>
0
 
actonwangCommented:

a typo:

>> var cb = _form.elements['test1'];

 change it to :

 var cb = _form.elements['toggle'];

Enjoy :)

Acton
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
chaitu chaituAuthor Commented:


I ma displaying 25 checboxes per page.yes i know that if i put same name i will get all vaues.by default all checkboxes will be checked but my requirment is if user check the checkbox only the value should be populated in the servlet;i can't use struts.it is only normal jsp.


actonwang,

how do i retrieve values in servlet i mean with what name.when i click next button the checked values should come.
0
 
chaitu chaituAuthor Commented:
by default all checkboxes are chedked ;i unchecked 2 boxes and again checked same checkboxes;

if i retrieve values using request.getParameterValues("checkHouse")  will  i get all values ??
0
 
a122178Commented:
Can you just write a javascript to call

http://localhost/<<servletName>>?checkHouse=12,1244,1441.

Past the parameter you need by POST or GET.

Will it be easier?

Hope this helps.
0
 
actonwangCommented:
>>if i retrieve values using request.getParameterValues("checkHouse")  will  i get all values ??

     yes. If you use my approach, it does. You can put my code in your test page and test it out.
     let me know if you have more questions.

Acton
0
 
actonwangCommented:
A trick:
 you can use "text" instead of "hidden" during your test so you can see how those values are enabled or disabled

 when you uncheck, those "text" boxes will be grey (disabled), you will not get those disabled values in your server side.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now