[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1342
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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