473,581 Members | 2,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to keep checkbox checked after click preview button

25 New Member
What are some simple ways to maintain checkbox value when user click preview button?

I want to submit post. Then when i click preview button, I want to keep all data on that page. When i choose monday and tuesday from 7 days in check box then when i click preview button i want monday and tuesday still checked and the others uncheck. The problem is when i click preview button all data that i just entered lost.
Apr 16 '10 #1
7 10631
chathura86
227 New Member
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     if (isset($_POST['day']))
  3.     {
  4.         foreach ($_POST['day'] as $selectedDay)
  5.             $selected[$selectedDay] = "checked";
  6.     }
  7. ?>
  8.  
  9. <form action="" method="post">
  10.     <input type="checkbox" name="day[]" <?php echo $selected['monday'] ?> value="monday" />monday<br />
  11.     <input type="checkbox" name="day[]" <?php echo $selected['tuesday'] ?> value="tuesday" />tuesday<br />
  12.     <input type="checkbox" name="day[]" <?php echo $selected['wednesday'] ?> value="wednesday" />wednesday<br />
  13.     <input type="checkbox" name="day[]" <?php echo $selected['thursday'] ?> value="thursday" />thursday<br />
  14.     <input type="checkbox" name="day[]" <?php echo $selected['friday'] ?> value="friday" />friday<br />
  15.     <input type="checkbox" name="day[]" <?php echo $selected['saturday'] ?> value="saturday" />saturday<br />
  16.     <input type="checkbox" name="day[]" <?php echo $selected['sunday'] ?> value="sunday" />sunday<br />
  17.     <br />
  18.     <br />
  19.     <input type="submit" name="Submit" value="Preview" />
  20. </form>
  21.  
Regards
Apr 16 '10 #2
amel86
25 New Member
@chathura86
I will try your code..thanx a lot chathura86
Apr 16 '10 #3
amel86
25 New Member
chathura..
i already try your code.
but how if the value like monday i want to change to other words that separated with space like 'no days'

when i put 'no days' in $selected['no days'] it show error like below:

The following error occurred when attempting to evaluate this template:

Parse error: syntax error, unexpected T_ENCAPSED_AND_ WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/newgadsc/public_html/includes/adminfunctions_ template.php(39 50) : eval()'d code on line 1403

This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish.
Apr 19 '10 #4
chathura86
227 New Member
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     if (isset($_POST['day']))
  3.     {
  4.         foreach ($_POST['day'] as $selectedDay)
  5.             $selected[$selectedDay] = "checked";
  6.     }
  7. ?>
  8.  
  9. <form action="" method="post">
  10.     <input type="checkbox" name="day[]" <?php echo $selected['monday'] ?> value="monday" />monday<br />
  11.     <input type="checkbox" name="day[]" <?php echo $selected['tuesday'] ?> value="tuesday" />tuesday<br />
  12.     <input type="checkbox" name="day[]" <?php echo $selected['wednesday'] ?> value="wednesday" />wednesday<br />
  13.     <input type="checkbox" name="day[]" <?php echo $selected['thursday'] ?> value="thursday" />thursday<br />
  14.     <input type="checkbox" name="day[]" <?php echo $selected['friday'] ?> value="friday" />friday<br />
  15.     <input type="checkbox" name="day[]" <?php echo $selected['saturday'] ?> value="saturday" />saturday<br />
  16.     <input type="checkbox" name="day[]" <?php echo $selected['sunday'] ?> value="sunday" />sunday<br />
  17.     <input type="checkbox" name="day[]" <?php echo $selected['no days'] ?> value="no days" />no days<br />
  18.     <br />
  19.     <br />
  20.     <input type="submit" name="Submit" value="Preview" />
  21. </form>
  22.  
did you mean something like this?

Regards
Apr 19 '10 #5
amel86
25 New Member
@chathura86
yes..exactly..b ut it show error when i put the code like this >>> $selected['no days']

it seem like it cant read space. how to slove it chathura?
Apr 19 '10 #6
chathura86
227 New Member
the code i just sent is working

Regards
Apr 19 '10 #7
amel86
25 New Member
ooo.. its worked!!.. mybe at first i make some mistake, thats why it doesnt work..

thank you chathura!!
Apr 19 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
7283
by: Steph | last post by:
Hello, Can someone tell me the script to use for having a change on the same page when using checkbox function ? For example, i would to check one condition and display dynamically a button if the condition is checked on the same page. Thanks in advance for your help
4
10524
by: moondaddy | last post by:
There are different times when I will have a group of checkboxes and need to force only one to be checked at a time. I would also like to do this client side and not require a postback. These checkboxes could be just a group of check boxes across the top of a page, or could be part of a datalist or datagrid. How do I make it so when a use...
5
3662
by: DotNetJunkies User | last post by:
1. i want to populate checkboxlist using javascript only at client side ....how can i do this..by populate word i mean that checkboxes should be checked or unchecked on some condition basis.... 2. after population there should be validation in checkboxlist..... that is if user clicks a button wihout checking any one of them(i.e. at least...
1
4491
by: dx | last post by:
I'm extremely frustrated with ASP.NET...again! To me this should be as simple as setting oCheckBox.Checked = True.. yet for some reason it isn't. I have a user control (ascx) that that has a checkbox and I can't get it to default to checked. I tried radiobuttons and experienced the same result.. can't start them as checked. The really...
2
5511
by: Ceema M via DotNetMonster.com | last post by:
Hello all, I have a nested repeater, which displays categories(parent repeater) and corresponding subcategories(child repeater). Both repeaters have checkboxes. When I check category checkbox and subcategory check boxes and click on submit button , I have to retrieve the corresponding categoryid and subcategory id, so that I can store it to...
0
2787
by: Keith | last post by:
I have a repeater control that contains a HeaderTemplate and an ItemTemplate. Each item contains a checkbox with an ID of chkReconciled, and the header contains a single checkbox with an ID of chkAll. I simply want to have chkAll be checked if every item in the repeater has its checkbox checked. In the code behind page, I can access the...
0
2261
by: Keith | last post by:
I have a repeater control that contains a HeaderTemplate and an ItemTemplate. Each item contains a checkbox with an ID of chkReconciled, and the header contains a single checkbox with an ID of chkAll. I simply want to have chkAll be checked if every item in the repeater has its checkbox checked. In the code behind page, I can access the...
1
4098
by: Kevin R | last post by:
This is one of the weirdest problems I have ever run into. I have had to trim down a bunch of code to give a sample that is more easily readable by those who will view this. Here is the problem: I dynamically add an htmlcheckbox to a webform in the pages render and set the checked value to true. When the page loads, if I remove the check...
0
1308
by: Frank Miverk | last post by:
Hi, I am not understanding how the Remember Me checkbox is supposed to work here. I have a LoginCtrl (asp.net 2.0, framework 2.0) and all I want to do is remember the user the next time if they previously checked the Remember Me checkbox. By default, on subsequent visits the Remember Me checkbox does not stay checked. I understand that...
0
1084
by: yogarajan | last post by:
Hi all, I need to display two sets of records. The second one should come under the first set of records and also second one uses the first one's unique id. for example, First table values id Show/hide button checkbox category 1 <Hide button> <checkbox> car (parent) ...
0
7789
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8144
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8301
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8169
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5361
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3803
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3820
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1400
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.