dsf23223 2013-07-24 11:06
浏览 71
已采纳

提交按钮和document.Form.submit()处理不同的脚本

I am still new to PHP and are not sure what would be the right thing to look for to solve my problem.

I have created a form that has the the same php page entered in the action field. In a few fields I want to use the $_GET values to narrow down the options for the user so I used onchange="document.MyForm.submit();". That works all well but at the end I want to use a submit button that sends the $_GET values to a different php page for updating my data base

Example:

<?php
    $SQLe = "SELECT Distinct Product FROM `Product_Table`  
    ORDER BY `Products`";
    echo '<select name="Product" onchange="document.MyForm.submit();"><option value="">All</option>';
    $rese = mysql_query($SQLe);
    while($vale=mysql_fetch_array($rese)) 
    {
      echo '<option ';
      if ($user_product==$vale['Product'] )
      echo " selected ";  echo 'value="'.$vale['Product']'">'.$vale["Product"].'</option>
';
                                }
        echo '</select>  ?>

The next input field uses the $_GET['Program'] variable to pull from the database specific data for the selected product.

  • 写回答

1条回答 默认 最新

  • dongsang6899 2013-07-24 11:46
    关注

    Following the idea to use AJAX would be the (best) solution. However it requires more effort. Also it might not be possible in all Environments. (A Customer, that cannot fill out a form, because of not working ajax requests is a gone customer :) )

    to do this with plain PHP, you can simple tell the (automated) submits apart from the one, invoked by the button:

     if (isset($_POST["button_name"])){
        //button clicked
     }else{
        //autoinvoked.
     }
    

    Now, the usal way would be to include your processing side, and maybe redirect afterwards, using header() when the user clicks the button.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥15 看一下OPENMV原理图有没有错误
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解
  • ¥15 有偿请教计算电磁学的问题涉及到空间中时域UTD和FDTD算法结合的
  • ¥15 vite打包后,页面出现h.createElement is not a function,但本地运行正常
  • ¥15 Java,消息推送配置
  • ¥15 Java计划序号重编制功能,此功能会对所有序号重新排序,排序后不改变前后置关系。
  • ¥15 关于哈夫曼树应用得到一些问题