Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 15-04-2009
Member
 
Join Date: Apr 2009
Posts: 55
How to set sessions for checkboxes

Hi,

I have an application and to select the yes or no option i have set an checkboxes, and for that i decided to keep sessions for that,whenever checkbox. Whenever i will check the option the sessions should be generated for the same, I have written the following code for the sessions to get executed.
Following is the code

Code:
<input id="repair" name="repair" type="checkbox" value="Repairs"checked="<?=$_SESSION[repair]?>" /> Repairs
this session works fine when i have input as a type text.

can you give a hint please?

Cheers,
Reply With Quote
  #2  
Old 15-04-2009
Member
 
Join Date: Dec 2008
Posts: 161
Re: How to set sessions for checkboxes

1) Try not to use short tags, use the full <?php echo $_SESSION ['repair'] ?> instead.

2) The HTML (not XHTML) way of defining a checkbox as checked was/is just by using the word 'checked' as oppose to the XHTML way which is checked="checked". For compatibility reasons, even if checked="" is set with no value the attribute 'checked' becomes true. If you want the checkbox to be unchecked you cant even have the empty checked=" "attribute in the tag.
Reply With Quote
  #3  
Old 15-04-2009
Member
 
Join Date: Jan 2009
Posts: 99
Re: How to set sessions for checkboxes

PHP checkboxes have a quirk in that if the checkbox is clear (false), browsers are not required to submit the control. If the control is set, the control is submitted as "control_name=control_name", but in the case of a clear checkbox, nothing is expected to be submitted.

Accordingly, it is import to set the property backing the checkbox to false when a form is rendered. If the checkbox submits back clear, it will remain false, if the form submits back, the field can be set to true to reflect the change.

However, if the form is being held in session scope, prematurely setting the value to false can be dangerous. If the form is never submitted back, the value will remain false. If the form is later committed to persistent store, an inadvertent change in state will occur.
Reply With Quote
  #4  
Old 15-04-2009
Member
 
Join Date: Dec 2008
Posts: 202
Re: How to set sessions for checkboxes

on each checkbox, you would have to individually check that session variables value, like this:

<input type="checkbox" name="chk1A" <%if Session("checkVar") = "1A" then Response.Write "checked"%> />This is checkbox 1A
<input type="checkbox" name="chk1B" <%if Session("checkVar") = "1B" then Response.Write "checked"%> />This is checkbox 1B
<input type="checkbox" name="chk1C" <%if Session("checkVar") = "1C" then Response.Write "checked"%> />This is checkbox 1C

if you were to have multiple checkbox values stored in the session variable, you would need to change your IF statement to:

<input type="checkbox" name="chk1A" <%if InStr( Session("checkVar"), "1A" ) > 0 then Response.Write "checked"%> />This ia checkbox 1A

This basically checks to see if the string "1A" is in the session variable, and if so, it'll check the checkbox.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to set sessions for checkboxes"
Thread Thread Starter Forum Replies Last Post
How to check all the checkboxes by using JavaScript? Dhano Software Development 6 12-04-2012 02:49 AM
Checkboxes Icons on Vista Desktop Nazmin Customize Desktop 3 25-04-2011 05:39 AM
How to validate checkboxes and radiolist in ASP.NET Chitrakala Software Development 5 14-01-2011 08:14 AM
Can we get checkboxes in XP like Windows Vista Michael Sabin Customize Desktop 6 24-09-2009 05:46 PM
How to create .Net custom checkboxes for listview Rover Software Development 2 11-06-2009 09:40 AM


All times are GMT +5.5. The time now is 07:09 AM.