submit button and onchange.submit

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • a10392
    New Member
    • Oct 2005
    • 3

    #1

    submit button and onchange.submit

    Hi,

    I'am triyng to create a form where i have 2 comboBox and 2 textbox, when the selection changes on the first combo , the content of second also changes. i have to use onchange=form.s ubmit()

    the problem is, i want to have a button to finish the selection and save all the data to a database, but if i have diferent forms, i will not get the last change on the text boxs, only th last change when i changed the combobox.

    Using the same form how can i know if it was the button pressed or the combochange that executed the submit ??

    here's an example

    Could you help me

    Thx
    Attached Files
  • a10392
    New Member
    • Oct 2005
    • 3

    #2
    submit button and onchange.submit

    Hi,

    i want to make a menu with 2 combos and 2 text boxes. when 1st combo changes, second combo is updated automatically (using onchange.submit ()), and i have 2 more text boxes.

    The problem is, i want to have a submit button, and when pressed it will execute a function in the index.php with the last changes from all the 4 inputs.

    - i have triyed in the same form, but this way, i dont know if the submit was executed by the button or by the change in the 1st combo box(onchange.su bmit()).
    - if i use another form i lose last data from text boxes

    Can someone help me !!!
    Here's the problem source.
    thanks in advance

    //##############
    //Index.php
    //##############
    include "funcs.php" ;
    print "INDEX state ".$state."<br>" ;
    print "INDEX city ".$city."<b r>";
    print "INDEX date ".$date."<b r>";
    print "INDEX phone ".$phone."<br>" ;

    if ($state=="")$st ate="stateA";//1;

    if ($savebutton==' 1')print "Function to save";

    $savebutton=0;
    ask_data($state ,$city,$date,$p hone);



    //############
    //FUNCS.PHP
    //#############


    function ask_data($state ,$city,$date,$p hone)
    {
    $states=array(' stateA','stateB ');
    $city1=array("S tateAcity1","St ateAcity2","Sta teAcity3");
    $city2=array("S tateBcity1","St ateBcity2","Sta teBcity3");
    ?>

    <table width="735" border="1" cellspacing="0" cellpadding="0" >
    <tr>
    <td align=center><b r>State&nbsp
    <form method="POST" enctype='applic ation/x-www-form-urlencoded' style="word-spacing: 0; margin-top: 0; margin-bottom: 0" name="formstate " action="index.p hp">
    <select name="state" onchange=formst ate.submit() >
    <? for ($i=0;$i<sizeof ($states);$i++)
    if ($state==$state s[$i])
    print "<option selected value=".$states[$i].">".$states[$i]."</option>";
    else
    print "<option value=".$states[$i].">".$states[$i]."</option>";
    ?>
    <input type='hidden' name='city' value=<?echo $city?>>
    <input type='hidden' name='phone' value=<?echo $phone?>>
    <input type='hidden' name='date' value=<?echo $date?>>

    </select>
    </td>
    <tr>
    <td align=center>
    City&nbsp<br>
    <?
    if ($state=='state A') $citys=$city1;
    else $citys=$city2;
    ?>
    <select name="city" onchange=formst ate.submit() >
    <?
    for ($i=0;$i<sizeof ($citys);$i++)
    if ($city==$citys[$i])
    print "<option selected value=".$citys[$i].">".$citys[$i]."</option>";
    else
    print "<option value=".$citys[$i].">".$citys[$i]."</option>";
    ?>
    <input type='hidden' name='phone' value=<?echo $phone?>>
    <input type='hidden' name='date' value=<?echo $date?>>
    </select>
    </td>
    <tr>
    <tr>
    </table>
    <table width="735" border="1" cellspacing="0" cellpadding="0" >
    <tr>
    <td align=center><b r>Phone&nbsp<br ><input type="text" size=10 MAXLENGTH=10 name="phone" value=<? echo $phone; ?> >
    </td>
    <tr>
    <td align=center><b r>Date&nbsp<br> <input type="text" size=6 MAXLENGTH=5 name="date" value=<? echo $date; ?> >
    </td>
    </table>
    </form>
    <form>
    <?
    print "FORM2 state ".$state."<br>" ;
    print "FORM2 city ".$city."<b r>";
    print "FORM2 date ".$date."<b r>";
    print "FORM2 phone ".$phone."<br>" ;
    ?>
    <input type='hidden' name='state' value=<?echo $state?>>
    <input type='hidden' name='city' value=<?echo $city?>>
    <input type='hidden' name='date' value=<?echo $date?>>
    <input type='hidden' name='phone' value=<?echo $phone?>>
    <input type='hidden' name='savebutto n' value='1'>

    <input type='submit' name='save' value='Save Data'>
    </form>
    <?
    }
    ?>

    Comment

    • rohypnol
      New Member
      • Dec 2007
      • 54

      #3
      I didn't understand much of what you said and your code is a mess. Stop using short tags and put double quotes around parameter values. But getting to your question, which I hope I got right and I hope this is what you need:

      *** FILE.PHP
      [PHP]<?php
      if (!isset($_REQUE ST['submit_btn']))
      {
      if (isset($_REQUES T['user_opt']))
      echo 'The option previously selected is: '.$_REQUEST['user_opt'];
      ?>

      <form method="post" action="file.ph p" name="dumbform" >
      <select name="user_opt" onchange="dumbf orm.submit()">
      <option value="1">one</option>
      <option value="2">two</option>
      <option value="3">three </option>
      </select>
      <input type="submit" name="submit_bt n">
      </form>

      <?php
      } else {
      DoSomething();
      ?>

      You have pressed the submit button.<br />
      user_opt = <?php echo $_REQUEST['user_opt']; ?>

      <?php
      }
      ?>[/PHP]

      Comment

      Working...