Checkboxes

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

    Checkboxes

    I have a two checkboxes in HTML:

    <input TYPE="checkbox" NAME="cc" VALUE="true"></td><td><b>Credi t
    Card</b></td></tr>

    <input TYPE="checkbox" NAME="cash" VALUE="true"></td><td><b>Compa ny
    Check</b>

    <input type=button onClick='<?php reviewpayment() ?>' value='Continue '
    style='font: 10pt Arial;

    The function works if I type into the function
    $cc = true;
    $cash = false;

    <?php
    function reviewpayment() {
    $validity = TRUE;

    if ($cc && cash) {
    echo 'javascript:ale rt(" Please select ONLY ONE type of payment ");';
    $validity = FALSE; }
    ............... ..... ?.

    Therefore the function is not receiving the input from the check boxes.

    How do I structure the script and HTML to send the input cc and cash in HTML
    to $cc and $cash in PHP?

    I have not been able to come up with a solution.

    Any suggestions?

    Thanks!


  • Geoff Berrow

    #2
    Re: Checkboxes

    I noticed that Message-ID: <G%a4c.51261$QP .42327@twister. rdc-kc.rr.com>
    from Ken contained the following:
    [color=blue]
    >How do I structure the script and HTML to send the input cc and cash in HTML
    >to $cc and $cash in PHP?[/color]

    You need to put the boxes in a <form></form> The form must have a
    method (post or get) If register globals is on the values of the
    checkboxes will be in $cc and $cash, if not they will be in the $_POST[]
    or $_GET[] arrays

    However, if you have two mutually exclusive choices, why not use a radio
    button?
    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/

    Comment

    • Ken

      #3
      Re: Checkboxes

      Geoff,

      Thanks for the suggestions.

      I do have the variables in between form tags. The actual script.

      <form name="payment" method="post">
      <table ALIGN=center border=0 cellspacing=6 cellpadding=0 bgcolor="#F6F9F 2">
      <tr><td bgcolor="D2E8DF " colspan=2><b>Se lect one type of
      payment</b></td></tr>
      <tr bgcolor="#F6F9F 2"><td><inpu t TYPE="checkbox" NAME="cc"
      VALUE="true"></td><td><b>Credi t Card</b></td></tr>
      <tr bgcolor="#F6F9F 2"><td><inpu t TYPE="checkbox" NAME="cash"
      VALUE="true"></td><td><b>Compa ny Check</b></td></tr> </table><br>
      <center><inpu t type=button onClick='<?php reviewpayment() ?>'
      value='Continue ' style='font: 10pt Arial; font weight: bold; color: 7F0738;
      background: FAB918;'></center>
      </form>

      I checked, register_global s is on.

      I have this script on the top of the page:
      <?php
      error_reporting (E_ALL);
      // error_reporting (0);
      session_start() ;
      ?>

      The function is in file: rev.php

      I have tried $_POST['cc']; $_SESSION['cc']; and $cc in the function
      reviewpayment() , nothing works.

      I have include("rev.ph p"); in the body of the html

      File rev.php
      function reviewpayment() {
      $validity = TRUE;
      $cc = $_SESSION['cc'];
      $cash = $_SESSION['cash'];

      if ($cc && $cash) {
      echo 'javascript:ale rt(" Please select ONLY ONE type of payment ");';
      $validity = FALSE; }
      }

      I appreciate your suggestions. Any other suggestions?

      -----------------------------------------------------
      php is new to me; I just started with php. I am familiar with JavaScript.
      In JavaScript, I use alert(cc); to look at the value of variables.

      I have not found a script that opens a box on the same page and displays a
      variables value in php. I have tired echo, but it look as if a new page
      must be opened to diplay the value.

      Is there another way to display variables in php?

      -------------------------------
      Thanks again!!
      Ken
      [color=blue][color=green]
      > >How do I structure the script and HTML to send the input cc and cash in[/color][/color]
      HTML[color=blue][color=green]
      > >to $cc and $cash in PHP?[/color]
      >
      > You need to put the boxes in a <form></form> The form must have a
      > method (post or get) If register globals is on the values of the
      > checkboxes will be in $cc and $cash, if not they will be in the $_POST[]
      > or $_GET[] arrays
      >
      > However, if you have two mutually exclusive choices, why not use a radio
      > button?
      > --
      > Geoff Berrow (put thecat out to email)
      > It's only Usenet, no one dies.
      > My opinions, not the committee's, mine.
      > Simple RFDs http://www.ckdog.co.uk/rfdmaker/[/color]


      Comment

      • Geoff Berrow

        #4
        Re: Checkboxes

        I noticed that Message-ID: <Bif4c.51288$QP .43356@twister. rdc-kc.rr.com>
        from Ken contained the following:
        [color=blue]
        >I appreciate your suggestions. Any other suggestions?[/color]

        Yeah, I was bit sleepy earlier.

        First of all, forget Javascript. JS is processed on the client machine
        (or not if they have it turned off). Most people using PHP only use JS
        for non critical processes (e.g.rollovers) . That way, the page still
        works if JS is turned off on the client machine.

        PHP is processed on the server. So your function call will be parsed
        when the script is delivered, not in response to an on screen event.

        To run the function the page has to have two states; the first state is
        all the code that is displayed before form is submitted, the second
        state is what is displayed /after/ the form is submitted. Of course you
        can have many more states.

        So I usually do something like this. By the way, you may need to make
        it a submit button, not sure about that without checking.

        if(isset($_POST['continue']))
        //if the button is pressed
        {
        //call the function
        reviewpayment() ;
        //clearly you do not have to use a JS popup here, you could simply print
        //html to the screen
        }

        //display form


        Hope this helps.



        --
        Geoff Berrow (put thecat out to email)
        It's only Usenet, no one dies.
        My opinions, not the committee's, mine.
        Simple RFDs http://www.ckdog.co.uk/rfdmaker/

        Comment

        • Geoff Berrow

          #5
          Re: Checkboxes

          I noticed that Message-ID: <jb8350dm48mobm rt23rq567hllvp3 r2ta9@4ax.com>
          from Geoff Berrow contained the following:
          [color=blue]
          >if(isset($_POS T['continue']))[/color]


          Oops.. That should be

          if(isset($_POST['name_of_button ']))

          However, this means the script only works if you press the button.
          Since some people sometimes submit by pressing the enter key, you can
          either check for the existence of some other variable that you know will
          definitely be there if the form is submitted, or, if no such variable
          exists, add a hidden field in the form and check for the existence of
          that.


          --
          Geoff Berrow (put thecat out to email)
          It's only Usenet, no one dies.
          My opinions, not the committee's, mine.
          Simple RFDs http://www.ckdog.co.uk/rfdmaker/

          Comment

          Working...