Connecting Tech Pros Worldwide Help | Site Map

Use a checkbox to define $var?

Mo
Guest
 
Posts: n/a
#1: Sep 26 '08
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
Jerry Stuckle
Guest
 
Posts: n/a
#2: Sep 26 '08

re: Use a checkbox to define $var?


Mo wrote:
Quote:
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.
jstucklex@attglobal.net
==================

Mo
Guest
 
Posts: n/a
#3: Sep 26 '08

re: Use a checkbox to define $var?


On Sep 26, 1:23*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Quote:
Mo wrote:
Quote:
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.
>
Quote:
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.
>
Quote:
Any common or creative ways to achieve this?
>
Quote:
~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
Mo
Guest
 
Posts: n/a
#4: Sep 26 '08

re: Use a checkbox to define $var?


On Sep 26, 1:38*pm, Mo <Mehile.Orl...@gmail.comwrote:
Quote:
On Sep 26, 1:23*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>
>
>
Quote:
Mo wrote:
Quote:
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.
>
Quote:
Quote:
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.
>
Quote:
Quote:
Any common or creative ways to achieve this?
>
Quote:
Quote:
~Mo
>
Quote:
No. *An unchecked checkbox will not send it's data to the server.
>
Quote:
What you can do is something like:
>
Quote:
if (isset($_POST['mycheckbox'])) {
* *... stuff here ...
>
Quote:
assuming the form is POSTed to the server and the checkbox is named
'mycheckbox', of course.
>
Quote:
You can even take this one further:
>
Quote:
if (isset($_POST['mycheckbox']) && $_POST['mycheckbox'] = 'myvalue') {
>
Quote:
This not only tests to see if the checkbox is set, but verifies the
value in the checkbox is 'myvalue'.
>
Quote:
--
==================
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
Captain Paralytic
Guest
 
Posts: n/a
#5: Sep 26 '08

re: Use a checkbox to define $var?


On 26 Sep, 21:42, Mo <Mehile.Orl...@gmail.comwrote:
Quote:
>
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.

Closed Thread