SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Frustrated with box code

    All,

    I found a good example of code to toggle a couple of radio buttons at:

    The example I chose, was the one shown for radio buttons, but I wanted to adapt it for checkboxes but could not get the right action.

    Most important, from other examples, one should be able to add to the "onclick" action the following:

    ; document.myform.submit()
    and be able to call the PHP processing. I am showing an IFRAME as an inset on the page and trying to switch between which data table is shown from the DB, but which button is selected. But somehow I can not get the PHP processing to work right. It either does not get called or gets called with all the same values, so I can not process the variance. I've put in the trap for my vars of:

    Code:
        foreach ($_POST as $key => $val) {
           echo "K=> $key V=> $val <br>";
        }
    Right now my code is:

    Code:
    <?php
    //    session_start();
        foreach ($_POST as $key => $val) {
           echo "K=> $key V=> $val <br>";
        }
        if (!isset($chk0) && !isset($chk1)) {
           $acc_chk = 'checked';
           $typ_chk = '';
        }
        echo "0=> $chk0 1=> $chk1 <br>";
        switch ($acc_chk) {
           case "":
        echo "Found Accounts! <br>";
           $acc_chk = 'checked';
           $typ_chk = '';
           break;
           case "checked":
        echo "Found Types! <br>";
           $acc_chk = '';
           $typ_chk = 'checked';
           break;
        }
        echo "A=> $acc_chk T=> $typ_chk C=> $chk_box <br>";
    
    //       <input name='chk' type=radio
    //          onclick=Set_Checked('chk1');
    //          document.accform.submit()>
    //             Type
    //       </input>
    ?>
    
    <html>
    <head>
    <STYLE>
    .button{
       width: 150px;                /* sets the size of the menu blocks */
       color: blue;
       font-family:verdana;
       font-weight:bold;
       font-size:12pt
    }
    </STYLE>
    <script type="text/javascript">
       function Set_Checked(type) {
          document.getElementById("chk0").style.display = "none"
          document.getElementById("chk1").style.display = "none"
          document.getElementById(type).style.display = ""
          this.form.submit()
       }
    </script>
    
    <!--link rel="stylesheet" type="text/css" href="acc_style.css"-->
    <title>Accounts Main</title>
    </head>
    
    <body>
    <p>
    <form method='POST' NAME='accform' ACTION="<?php $_SERVER['PHP_SELF']; ?>">
    <table width=95% border=2 align=center>
       <tr>
       <td width=150 align=left rowspan=6 valign=top bgcolor=#aaaaaa>
           <?php include('acc_men_l.php'); echo $l_men; ?>
       </td>
       <td colspan=2 align=center>
           <font face=verdana size=3><b>Accounts Mains</b></font>
       </td>
       </tr>
    
       <tr>
       <td width=50% align=left>
           <input type="hidden" name="chk0" value="true">
           <input name='chk' type=radio checked
              onclick=Set_Checked('chk0')>
                 Accounts
           </input>
       </td>
    
       <td width=50% align=right>
           <input type="hidden" name="chk1" value="false">
           <input name='chk' type=radio
              onclick=Set_Checked('chk1')>
                 Type
           </input>
       </td>
       </tr>
    
       <tr>
       <td colspan=2>
           <IFRAME WIDTH=95% HEIGHT=350 id='acc' frameborder="0"
              src=acc_db_main.php?tbl_val='acc' style="">
           </IFRAME>
           <IFRAME WIDTH=95% HEIGHT=350 id='typ' frameborder="0"
              src=acc_db_main.php?tbl_val='typ' style="display:none">
           </IFRAME>
       </td>
       </tr>
    
       <tr>
       <td>&nbsp;</td>
       </tr>
    
       <tr>
       <td align=center colspan=2>
          <input type="hidden" name="action" value="submitted">
          <input type=submit name=sync value=Synchronize>
       </td>
       </tr>
    </table>
    </form>
    
    </body>
    </html>
    and it is not calling the PHP processing.

    What do I need to change?

    Thanks!

    OMR

  2. #2
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you don't show us the HTML code that has those radio buttons we will just have to guess.

    My guess is that you have <form> tag without method="POST".

    Either make <form method="POST" .........> or change $_POST to $_GET in php.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2008
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok,

    Here is complete code:

    Code:
    <?php
    if(isset($_POST) && !empty($_POST)){
        foreach($_POST as $key => $val) {
           echo "K=> $key V=> $val <br>";
        }
    }
    $cb_1 = $_POST['cb1'];
    $cb_2 = $_POST['cb2'];
    echo "1=> $cb_1 2=> $cb_2 <br>";
    if ($cb_1=='' && $cb_2=='cb2Value') {
       $cb_1 = 'checked';
       $cb_2 = '';
       $tb_val = 'Check One';
    } else {
       $cb_1 = '';
       $cb_2 = 'checked';
       $tb_val = 'Check Two';
    }
    ?>
    </STYLE>
    <script type="text/javascript">
       function Set_Checked(type) {
          document.getElementById("cb1").style.display = "none"
          document.getElementById("cb2").style.display = "none"
          document.getElementById(type).style.display = ""
          this.form.submit()
       }
    </script>
    <br />
    <br />
    <form method='POST' NAME='theForm' ACTION="<?php $_SERVER['PHP_SELF']; ?>">
    <input type="radio" name="cb1" value="cb1Value" onClick="document.theForm.submit()"
       <?php echo $cb_1; ?> />CB1<br />
    <input type="radio" name="cb2" value="cb2Value" onClick="document.theForm.submit()"
       <?php echo $cb_2; ?> />CB2<br />
    <input type="text" name="tb1" value="<?php echo $tb_val; ?>" />
    </form>
    My IFRAME code is:

    Code:
    <?php
    //    session_start();
        foreach ($_POST as $key => $val) {
           echo "K=> $key V=> $val <br>";
        }
        if (!isset($chk0) && !isset($chk1)) {
           $acc_chk = 'checked';
           $typ_chk = '';
        }
        echo "0=> $chk0 1=> $chk1 <br>";
        switch ($acc_chk) {
           case "":
        echo "Found Accounts! <br>";
           $acc_chk = 'checked';
           $typ_chk = '';
           break;
           case "checked":
        echo "Found Types! <br>";
           $acc_chk = '';
           $typ_chk = 'checked';
           break;
        }
        echo "A=> $acc_chk T=> $typ_chk C=> $chk_box <br>";
    
    //       <input name='chk' type=radio
    //          onclick=Set_Checked('chk1');
    //          document.accform.submit()>
    //             Type
    //       </input>
    ?>
    
    <html>
    <head>
    <STYLE>
    .button{
       width: 150px;                /* sets the size of the menu blocks */
       color: blue;
       font-family:verdana;
       font-weight:bold;
       font-size:12pt
    }
    </STYLE>
    <script type="text/javascript">
       function Set_Checked(type) {
          document.getElementById("chk0").style.display = "none"
          document.getElementById("chk1").style.display = "none"
          document.getElementById(type).style.display = ""
          this.form.submit()
       }
    </script>
    
    <!--link rel="stylesheet" type="text/css" href="acc_style.css"-->
    <title>Accounts Main</title>
    </head>
    
    <body>
    <p>
    <form method='POST' NAME='accform' ACTION="<?php $_SERVER['PHP_SELF']; ?>">
    <table width=95% border=2 align=center>
       <tr>
       <td width=150 align=left rowspan=6 valign=top bgcolor=#aaaaaa>
           <?php include('acc_men_l.php'); echo $l_men; ?>
       </td>
       <td colspan=2 align=center>
           <font face=verdana size=3><b>Accounts Mains</b></font>
       </td>
       </tr>
    
       <tr>
       <td width=50% align=left>
           <input type="hidden" name="chk0" value="true">
           <input name='chk' type=radio checked
              onclick=Set_Checked('chk0')>
                 Accounts
           </input>
       </td>
    
       <td width=50% align=right>
           <input type="hidden" name="chk1" value="false">
           <input name='chk' type=radio
              onclick=Set_Checked('chk1')>
                 Type
           </input>
       </td>
       </tr>
    
       <tr>
       <td colspan=2>
           <IFRAME WIDTH=95% HEIGHT=350 id='acc' frameborder="0"
              src=acc_db_main.php?tbl_val='acc' style="">
           </IFRAME>
           <IFRAME WIDTH=95% HEIGHT=350 id='typ' frameborder="0"
              src=acc_db_main.php?tbl_val='typ' style="display:none">
           </IFRAME>
       </td>
       </tr>
    
       <tr>
       <td>&nbsp;</td>
       </tr>
    
       <tr>
       <td align=center colspan=2>
          <input type="hidden" name="action" value="submitted">
          <input type=submit name=sync value=Synchronize>
       </td>
       </tr>
    </table>
    </form>
    
    </body>
    </html>
    Thanks!

    OMR


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •