【问题标题】:Submitting Form using an option from drop down list使用下拉列表中的选项提交表单
【发布时间】:2014-08-07 22:55:33
【问题描述】:
<html>
<head>
<title>         </title>
<script type="text/javascript">
  var datefield=document.createElement("input");
  datefield.setAttribute("type", "date");
  if (datefield.type!="date"){ //if browser doesn't support input type="date", load   
files for jQuery UI Date Picker
    document.write('<link type="text/css" href="scripts/jquery-ui.css" rel="stylesheet" 
/>\n');
    document.write('<script src="scripts/jquery.min.js"><\/script>\n');
    document.write('<script src="scripts/jquery-ui.min.js"><\/script>\n');
           }
</script>

   <script>
     if (datefield.type!="date"){ //if browser doesn't support input type="date",   
    initialize date picker widget:
    jQuery(function($){ //on document.ready
        $('#date').datepicker();
    });
    }
    </script>
    <style type="text/css">
    body{
    margin-left: 10%;
    margin-right: 10%;

    font-family: sans-serif;
    }
    </style>
    </head>
    <body>
    <h1 align="center">Date Sheet Feed </h1>
    <form name="frm" method="post" action='<?php echo $_SERVER['PHP_SELF']; ?>'>
    <table width="50%" border="1" cellpadding="3" cellspacing="3" align="center">
    <?php 
    $value1=array();
    $select_query="SELECT Distinct branch FROM department";
    $result=mysqli_query($dbcon,$select_query);
     if(!$result) die("Fail".mysqli_error($dbcon));

    while($row=mysqli_fetch_array($result))
    {
        $value1[]=$row['branch'];
    }

    ?>
    <tr><td>Branch<td><select name="branch" id="branch"  onchange="document.frm.submit();">
                 <option >Select Branch</option>
                   <?php  
                         foreach($value1 as $gets)
                         {
                        ?>
                           <option value='<?php echo $gets;?>' <?php   
    if(true===isset($_POST['branch']))
                          {
                            print($gets==$_POST['branch'] ? ' selected="selected"' :   
    '');
                     }     ?> > <?php echo $gets; ?></option> 

                      <?php 
                      }
               ?>
            </select></td></tr>

我想使用下拉列表中的选项提交表单。但表格没有被提交。请帮帮我

【问题讨论】:

  • 我浏览了您的代码,但没有找到结束 &lt;/form&gt; 标记。
  • 您需要附加jquery更改功能以在下拉值.change上提交您的表单
  • 存在于主代码中

标签: javascript php jquery html forms


【解决方案1】:

您缺少几个要关闭的标签:

    </table>
</form>

并且您应该在下拉更改时绑定和事件处理程序。

$(document).ready(function(){
    $("#branch").change(function(){
        $("form[name=frm]").submit();
    });
});

【讨论】:

    【解决方案2】:

    缺少标签。

     </table>
    </form>
    

    只需添加以下代码。

    <select onchange="this.form.submit()">
        ...
    </select>
    

    例如:

    <!DOCTYPE html>
    <html>
      <head>
      </head>
      <body>
        <form action="index.html" onsubmit="alert('Form Submitted');" method="post">
        <select name="data" onchange="this.form.submit()">
          <option value="orange">orange</option>
          <option value="yellow">yellow</option>
          <option value="blue">blue</option>
          <option value="pink">pink</option>
          <option value="lightdark">lightdark</option>
        </select>
        </form>
      </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-18
      • 1970-01-01
      • 1970-01-01
      • 2015-08-30
      相关资源
      最近更新 更多