473,386 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how to keep checkbox checked after click preview button

25
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

✓ answered by chathura86

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

7 10605
chathura86
227 100+
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
@chathura86
I will try your code..thanx a lot chathura86
Apr 16 '10 #3
amel86
25
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(3950) : 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 100+
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
@chathura86
yes..exactly..but 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 100+
the code i just sent is working

Regards
Apr 19 '10 #7
amel86
25
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
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...
4
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...
5
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.......
1
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...
2
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...
0
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...
0
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...
1
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:...
0
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...
0
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 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...

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.