how can i check the button is clicked?

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

    how can i check the button is clicked?

    Hi, this is my problem. I have two php files such as a.php, b.php
    a.php :
    <?php
    require("b.php" );

    if($_GET['submit'] == "")
    {
    MainFrame();
    }
    else if ($_GET['submit'] == "Receiving" )
    {
    Receiving();
    }
    else {
    foo1();
    }
    ?>

    b.php :
    <?php

    function MainFrame()
    {
    ........many choices , one of them is "Receiving"
    }
    function Receiving()
    {<form action = \"Receiving.php \" method=\"GET\">
    ............... .
    <td><select name =\"Receiving_Re ceivedBy\">");
    while($Row = mysql_fetch_arr ay($Result)){
    print("<option value =\"$Row[EmployeeID]\">$Row[Employee_Name]
    </option>");
    }
    print(" </select></td></tr>

    <input type =\"button\" name=\"Change_P art\" value=\"Add\">
    <input type =\"button\" name=\"Change_P art1\" value=\"Edit\">
    ............... ............... .
    ............... ....
    <input type =\"submit\" name=\"Receivin g_submit\"
    value=\"Submit\ ">
    </form>
    }
    ?>
    What i want:
    after i click the button and its value is Add , do Add function to add
    the employee in the database
    after I click the button and its value is edit , do Edit function to
    edit the information in particular employee.
    Finally, i get all information and click the submit to save the data
    in the database. However, i dont know how can i check the button is
    clicked. Do i need to write javascript. Coz i am not familiar with
    javascript. Do i have other method? i know i cannot use type=submit
    again coz form cannot nest.
    Thanks
    Krista
  • Tom Thackrey

    #2
    Re: how can i check the button is clicked?


    On 24-Dec-2003, ywan_ip@hotmail .com (Krista) wrote:
    [color=blue]
    > Hi, this is my problem. I have two php files such as a.php, b.php
    > a.php :
    > <?php
    > require("b.php" );
    >
    > if($_GET['submit'] == "")
    > {
    > MainFrame();
    > }
    > else if ($_GET['submit'] == "Receiving" )
    > {
    > Receiving();
    > }
    > else {
    > foo1();
    > }
    > ?>
    >
    > b.php :
    > <?php
    >
    > function MainFrame()
    > {
    > .......many choices , one of them is "Receiving"
    > }
    > function Receiving()
    > {<form action = \"Receiving.php \" method=\"GET\">
    > ............... .
    > <td><select name =\"Receiving_Re ceivedBy\">");
    > while($Row = mysql_fetch_arr ay($Result)){
    > print("<option value =\"$Row[EmployeeID]\">$Row[Employee_Name]
    > </option>");
    > }
    > print(" </select></td></tr>
    >
    > <input type =\"button\" name=\"Change_P art\" value=\"Add\">
    > <input type =\"button\" name=\"Change_P art1\" value=\"Edit\">
    > ............... ............... .
    > ............... ....
    > <input type =\"submit\" name=\"Receivin g_submit\"
    > value=\"Submit\ ">
    > </form>
    > }
    > ?>
    > What i want:
    > after i click the button and its value is Add , do Add function to add
    > the employee in the database
    > after I click the button and its value is edit , do Edit function to
    > edit the information in particular employee.
    > Finally, i get all information and click the submit to save the data
    > in the database. However, i dont know how can i check the button is
    > clicked. Do i need to write javascript. Coz i am not familiar with
    > javascript. Do i have other method? i know i cannot use type=submit
    > again coz form cannot nest.[/color]

    You named the submit buttons Change_Part and Change_Part1. You need to test
    for those names

    if ($_POST['Change_Part']=='Add')

    What I do is name all the submit buttons the same, usually 'submit', then I
    code something like:

    if (!empty($_POST['submit']))
    $button = $_POST['submit'];
    else
    $button = '';
    if ($button == 'Add')
    ....
    else if ($button == 'Edit')
    ....
    else if ($button == 'Delete')
    ...

    --
    Tom Thackrey

    tom (at) creative (dash) light (dot) com
    do NOT send email to jamesbutler@wil lglen.net (it's reserved for spammers)

    Comment

    Working...