By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,342 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

Use a checkbox to define $var?

P: n/a
Mo
Newbie question: Is there a way to have an checkbox input define a
var?
I have a report for sales activity for a user definable date range.

I want to include a "Last Month" checkbox in my form section of the
page.
I already have the code to create the dates for this, but am hoping to
use an IF/ELSE with the checkbox to automatically populate the input
text boxes IF the box is checked.

Any common or creative ways to achieve this?

~Mo
Sep 26 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Mo wrote:
Newbie question: Is there a way to have an checkbox input define a
var?
I have a report for sales activity for a user definable date range.

I want to include a "Last Month" checkbox in my form section of the
page.
I already have the code to create the dates for this, but am hoping to
use an IF/ELSE with the checkbox to automatically populate the input
text boxes IF the box is checked.

Any common or creative ways to achieve this?

~Mo
No. An unchecked checkbox will not send it's data to the server.

What you can do is something like:

if (isset($_POST['mycheckbox'])) {
... stuff here ...

assuming the form is POSTed to the server and the checkbox is named
'mycheckbox', of course.

You can even take this one further:

if (isset($_POST['mycheckbox']) && $_POST['mycheckbox'] = 'myvalue') {

This not only tests to see if the checkbox is set, but verifies the
value in the checkbox is 'myvalue'.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Sep 26 '08 #2

P: n/a
Mo
On Sep 26, 1:23*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Mo wrote:
Newbie question: Is there a way to have an checkbox input define a
var?
I have a report for sales activity for a user definable date range.
I want to include a "Last Month" checkbox in my form section of the
page.
I already have the code to create the dates for this, but am hoping to
use an IF/ELSE with the checkbox to automatically populate the input
text boxes IF the box is checked.
Any common or creative ways to achieve this?
~Mo

No. *An unchecked checkbox will not send it's data to the server.

What you can do is something like:

if (isset($_POST['mycheckbox'])) {
* *... stuff here ...

assuming the form is POSTed to the server and the checkbox is named
'mycheckbox', of course.

You can even take this one further:

if (isset($_POST['mycheckbox']) && $_POST['mycheckbox'] = 'myvalue') {

This not only tests to see if the checkbox is set, but verifies the
value in the checkbox is 'myvalue'.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
What about prior to the form getting submitted (no $_POST data yet)?
Can we do this in PHP, or would I have to look for some other
solution?

~Mo
Sep 26 '08 #3

P: n/a
Mo
On Sep 26, 1:38*pm, Mo <Mehile.Orl...@gmail.comwrote:
On Sep 26, 1:23*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Mo wrote:
Newbie question: Is there a way to have an checkbox input define a
var?
I have a report for sales activity for a user definable date range.
I want to include a "Last Month" checkbox in my form section of the
page.
I already have the code to create the dates for this, but am hoping to
use an IF/ELSE with the checkbox to automatically populate the input
text boxes IF the box is checked.
Any common or creative ways to achieve this?
~Mo
No. *An unchecked checkbox will not send it's data to the server.
What you can do is something like:
if (isset($_POST['mycheckbox'])) {
* *... stuff here ...
assuming the form is POSTed to the server and the checkbox is named
'mycheckbox', of course.
You can even take this one further:
if (isset($_POST['mycheckbox']) && $_POST['mycheckbox'] = 'myvalue') {
This not only tests to see if the checkbox is set, but verifies the
value in the checkbox is 'myvalue'.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

What about prior to the form getting submitted (no $_POST data yet)?
Can we do this in PHP, or would I have to look for some other
solution?

~Mo
I'm kinda thinking along the lines of those "Yes, I agree to terms and
conditions" type checkboxes which, just by clicking them, do something
(such as enable/disable submit button).
~ Mo
Sep 26 '08 #4

P: n/a
On 26 Sep, 21:42, Mo <Mehile.Orl...@gmail.comwrote:
>
I'm kinda thinking along the lines of those "Yes, I agree to terms and
conditions" type checkboxes which, just by clicking them, do something
(such as enable/disable submit button).
~ Mo
This bit would be done in Javascript.

Sep 26 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.