 |
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

April 17th, 2007, 05:55 AM
|
Registered User
|
|
Join Date: Apr 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

April 20th, 2007, 05:38 AM
|
Friend of Wrox
|
|
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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
|

April 23rd, 2007, 04:12 AM
|
Registered User
|
|
Join Date: Apr 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

April 24th, 2007, 07:06 AM
|
Friend of Wrox
|
|
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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
|

April 25th, 2007, 08:26 AM
|
Registered User
|
|
Join Date: Apr 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
How to do second way? plz explain with example.
and how to return string from javascript function to jsp hidden field?
Monali Swarge
|

April 26th, 2007, 11:29 PM
|
Friend of Wrox
|
|
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hi,
- Rakesh
|

April 26th, 2007, 11:33 PM
|
Friend of Wrox
|
|
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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
|

April 27th, 2007, 07:07 AM
|
Registered User
|
|
Join Date: Apr 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Rakesh!! The problem is solved.
Regards
Monali Swarge
|

June 6th, 2007, 09:03 AM
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
|
|
How do you store checkbox selections in a hidden field?
|

June 7th, 2007, 11:35 PM
|
Friend of Wrox
|
|
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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
|
|
 |