Use a checkbox to define $var?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mo

    #1

    Use a checkbox to define $var?

    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

    #2
    Re: Use a checkbox to define $var?

    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.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Mo

      #3
      Re: Use a checkbox to define $var?

      On Sep 26, 1:23 pm, Jerry Stuckle <jstuck...@attg lobal.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...@attgl obal.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

      Comment

      • Mo

        #4
        Re: Use a checkbox to define $var?

        On Sep 26, 1:38 pm, Mo <Mehile.Orl...@ gmail.comwrote:
        On Sep 26, 1:23 pm, Jerry Stuckle <jstuck...@attg lobal.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...@attgl obal.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

        Comment

        • Captain Paralytic

          #5
          Re: Use a checkbox to define $var?

          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.

          Comment

          Working...