Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java Open Source > Struts
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Struts section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 17th, 2007, 05:55 AM
Registered User
 
Join Date: Apr 2007
Location: Pune, Maharashtra, India.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to mona_1dec
Default how to store checkbox value in database

Hi ,
  I want to store value of checkbox which are checked in MySQL database how to do it?

this is in my jsp page.

<input type="checkbox" id="sun" name="sunday" value="Sunday" disabled="true" />Sunday
          <input type="checkbox" id="mon" name="monday" value="Monday" disabled="true" />Monday
          <input type="checkbox" id="tues" name="tuesday" value="Tuesday" disabled="true" />Tueaday
          <input type="checkbox" id="wed" name="wednesday" value="Wednesday" disabled="true" />Wednesday
          <input type="checkbox" id="thurs" name="thursday" value="Thursday" disabled="true" />Thursday
          <input type="checkbox" id="fri" name="friday" value="Friday" disabled="true"/>Friday
          <input type="checkbox" id="sat" name="saturday" value="Saturday" disabled="true" />Saturday<br><br>

please help me.
thanks in advance.

Monali Swarge
Reply With Quote
  #2 (permalink)  
Old April 20th, 2007, 05:38 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hyderabad, A.P., India.
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,

Declare an array varible with a name days in the form bean class and change the name attribute in the page to days,or else you can use struts taglibraries and set the property attribute to days then the selected check boxes will be stored in that array, use it to store in the database.
If you are using plain JSP/Servlets then give the name attribute for the check boxes as days and in the servlet use request.getParameterValues() method to get the array of values [selected check boxes] as a String array.

Regards,
Rakesh
Reply With Quote
  #3 (permalink)  
Old April 23rd, 2007, 04:12 AM
Registered User
 
Join Date: Apr 2007
Location: Pune, Maharashtra, India.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to mona_1dec
Default

Thanks,
  But now I want to store 1 if checked and 0 if not. i.e. if I have 5 checkboxes and is I check 1st and 3rd checkboxes then I should have it in the form 10100.. and I want to store it in database..

  I used a javascript code in my jsp page to check status of checkboxes.. but I dont know how to return this string to ActionForm..

function checkStatus()
        {
         wday=document.forms[0].wday
         weektxt=""
         for (i=0;i< wday.length;++i)
           {
            if (wday[i].checked)
             {
              weektxt=weektxt + 1
             }
            else
             {
              weektxt=weektxt + 0
             }
           }

         mday=document.forms[0].mday
         monthtxt=""
         for (i=0;i< mday.length;++i)
           {
            if (mday[i].checked)
             {
              monthtxt=monthtxt+ 1
             }
            else
             {
              monthtxt=monthtxt + 0
             }
           }
          return weektxt;
          return monthtxt;
        }

can u plz help me? or if there is some another way plz suggest.
Thanks in advance.

Monali Swarge
Reply With Quote
  #4 (permalink)  
Old April 24th, 2007, 07:06 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hyderabad, A.P., India.
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,
You can use a hidden variable to store the formatted text and define a string variable in the form bean to have this value.

Other way would be declare an array variable in the form bean and a method to generate the formatted text [ex. 100101] based on the values in the array. Call this method to get the formatted text and store it in the database.

Regards,
Rakesh
Reply With Quote
  #5 (permalink)  
Old April 25th, 2007, 08:26 AM
Registered User
 
Join Date: Apr 2007
Location: Pune, Maharashtra, India.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to mona_1dec
Default

How to do second way? plz explain with example.
and how to return string from javascript function to jsp hidden field?

Monali Swarge
Reply With Quote
  #6 (permalink)  
Old April 26th, 2007, 11:29 PM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hyderabad, A.P., India.
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,


- Rakesh
Reply With Quote
  #7 (permalink)  
Old April 26th, 2007, 11:33 PM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hyderabad, A.P., India.
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,
Sorry! about the above post.

Think you've declared a hidden variable in the form tag like
<input type="hidden" name="week_days" id="week_days" value=""/>

and use a script block to set the value like

document.getElementById("week_days").value = "processed value";

The processed value is the one you've generated [100100]. If you submit the form then this value is available to you in the request object use request.getParameter("week_days")

Hope its clear to you.

Regards,
Rakesh
Reply With Quote
  #8 (permalink)  
Old April 27th, 2007, 07:07 AM
Registered User
 
Join Date: Apr 2007
Location: Pune, Maharashtra, India.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to mona_1dec
Default

Thanks Rakesh!! The problem is solved.

Regards

Monali Swarge
Reply With Quote
  #9 (permalink)  
Old June 6th, 2007, 09:03 AM
Friend of Wrox
Points: 1,107, Level: 13
Points: 1,107, Level: 13 Points: 1,107, Level: 13 Points: 1,107, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2004
Location: , , .
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
Default

How do you store checkbox selections in a hidden field?

Reply With Quote
  #10 (permalink)  
Old June 7th, 2007, 11:35 PM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hyderabad, A.P., India.
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,

Quote:
quote:Originally posted by gilgalbiblewheel
 How do you store checkbox selections in a hidden field?
In the second post by Monali Swarge, you can see a java script method checkStatus() which will give you some form of formatted string [see the above posts for clarification about how the string is generated] that string is stored in the hidden field using the script document.getElementById("week_days").value = "processed value";.

Regards,
Rakesh
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to store 2 checkbox values in separate lines i jennypretty Classic ASP Basics 1 June 3rd, 2007 06:39 PM
multiple checkbox store one field mateenmohd Classic ASP Basics 0 June 11th, 2006 01:39 AM
Store Checkbox values in MySQL Database jkilgore Beginning PHP 1 July 7th, 2005 03:43 PM
store machine name in database alyeng2000 ASP.NET 1.0 and 1.1 Professional 5 September 29th, 2004 10:55 PM
Where could get the Music Store Database? cash Java Databases 2 February 21st, 2004 08:48 PM



All times are GMT -4. The time now is 06:44 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.