473,473 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Retaining checkbox state on redisplay

58 New Member
Greetings everyone !
I seek some help to retain checkbox state on redisplay.I only have one optional checkbox to indicate whether it's the user's first visit to the site

Form1:
Expand|Select|Wrap|Line Numbers
  1. <INPUT type="checkbox" name="guest" value="yes">
  2.  
[Please use CODE tags when posting source code. Thanks! --pbmods]

I tried it as below on Form2,but didnt work for me

Form2:
Expand|Select|Wrap|Line Numbers
  1. <INPUT type="checkbox" name="guest" value="yes" <?php if(guest == "yes"){echo " CHECKED";}?>>
Any ideas?

Thank you
Jun 18 '07 #1
4 3334
epots9
1,351 Recognized Expert Top Contributor
it would be:
[PHP]
if($_POST["guest"] == "yes")
[/PHP]

or:
[PHP]
if($_GET["guest"] == "yes")
[/PHP]

if your first form has the method set to post then use the first example, if it is set to get then use the second example.

good luck
Jun 18 '07 #2
Jankie
58 New Member
Thank you very much Epots9 ! really appreciate it
And good luck to you, too
Jun 18 '07 #3
pbmods
5,821 Recognized Expert Expert
Heya, Jankie.

If you're curious, when you do this:
Expand|Select|Wrap|Line Numbers
  1. <?php if(guest == "yes"){echo " CHECKED";}?>
What PHP is actually doing is looking for a constant named 'guest'. Since (presumably), you didn't define a constant (using the define keyword), PHP will instead use the string literal 'guest'. Since 'guest' will never == "yes", your script will never echo " CHECKED".

Here's an explanation of why this happens (used to explain array indexes, but the principle is the same for strings):
http://us2.php.net/manual/en/languag....array.foo-bar

P.S., for full XHTML compliance, you should echo " checked=\"checked\"" instead ~_^
Jun 18 '07 #4
Jankie
58 New Member
pbmods
Interesting explanation,
i actually meant it the correct way,but sometimes as it turns out in my first code,the concept alone does not kill it,php-aware is essential
Thank you all for sharing this insight !
Jun 18 '07 #5

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

Similar topics

3
by: Rich | last post by:
I have a form with 2 check boxes. One of the check boxes is used to specify that the user is a "primary contact." When I check the primary contact box I want a second box for "standard contact"...
5
by: Leo J. Hart IV | last post by:
Hello, I'm hoping someone can help me out. I was wondering if the Enabled property of a CheckBox or RadioButton server control is stored in the ViewState. If not, is there some way to to add...
1
by: mschoup | last post by:
I have a simple aspx page(WebForm1.aspx) with a HyperLink, LinkButton, and two CheckBoxes. When I select a CheckBox and then click the LinkButton, the CheckBox retains state. When I select the...
2
by: CC | last post by:
Hi, We are populating a CheckedListBox from a database. Based on a selection by the user, the CheckedListBox either contains ALL possible members of a set, or a subset of possible members. The...
1
by: Scott H | last post by:
I have a page with several server controls placed on there at design time, including a blank table control. During runtime I add some controls to the table, including some checkboxes, which I...
10
by: rn5a | last post by:
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked....
9
by: mike7510uk | last post by:
Hi, I am using a gridview with a templatefield containing a checkbox. I want to update the database with a 1 or 0 depending on if a checkbox is checked or unchecked (then use the 1 or 0 later on...
4
by: virk1711 | last post by:
I want to retain the state of checkboxes after the submit button has been clicked. What it is currently doing is that it is resetting the checkboxes after the submit button is clicked. My code is...
13
by: ramprakashjava | last post by:
hi, i hav "java.lang.NullPointerException" error while Deleting table records using checkbox in jsp here i enclosed files help quickly plzzz.. ...
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...
0
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.