472,371 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 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 10507
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 ...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

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.