简体   繁体   English

获取没有提交按钮的选定下拉值

[英]get selected dropdown value without submit button

I have 2 dropdown outside the html table generated by PHP code. 我在PHP代码生成的html表之外有2个下拉列表。 I have submit button in this table 我在此表中有提交按钮
as explained by following code. 如以下代码所述。

 <!doctype html>
            Select Year:
                   <select name=\"year\" id=\"year\"  style="width: 200px">
                      <option value=\"2014\">2014</option>
                      <option value=\"2015\">2015</option>
                    </select>

                Select Trimester: 
                    <select name=\"trimester\" id=\"trimester\" style="width: 200px">
                        <option value=\"1st\">1st</option>
                        <option value=\"2nd\">2nd</option>
                        <option value=\"3rd\">3rd</option>
                    </select> 

<?php
     while($row = mysql_fetch_array($result)){
                      $ict_id= $row['id'];
                      $name= $row['name'];
          echo "<tr><form name=\"form$id\" id=\"form$id\"><td>".$name."</td>

        <td>
          <select name=\"absent$id\" id=\"absent$id\" style=\"width: 200px\">
            <option value=\"1\">1</option>
            <option value=\"2\">2</option>
          </select>
        </td>

        <td>
          <select name=\"creative$id\" id=\"creative$id\" style=\"width: 200px\">
            <option value=\"1\">1</option>
            <option value=\"2\">2</option>
          </select>
        </td>

        <td>
          <select name=\"problem$id\" id=\"problem$id\" style=\"width: 200px\">
            <option value=\"1\">1</option>
            <option value=\"2\">2</option>
          </select>
        </td>

    <td>
    <input type=\"button\" name=\"submit$id\"  id=\"submit$id\" value=\"Submit\"      onclick=\"getVal(this.id)\">
?>

On clicking this button it loads following javascript function. 在单击此按钮时,它将加载以下javascript函数。

function getVal(clicked_id){

}

My problem is how can I get the selected value of year and trimester and use inside the getVal function . 我的问题是如何获取选定的年和三个月的值并在getVal函数中使用。

Any helps are welcomed. 欢迎任何帮助。

Add onchange event to the select element and pass id to this like this: onchange事件添加到select元素,并将ID传递给此元素,如下所示:

<select onchange="getVal(this.id)" name=\"absent$id\" id=\"absent$id\" style=\"width: 200px\">

Call getVal function like this: 像这样调用getVal函数:

function getVal(clicked_id){
    alert(clicked_id);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取选定的下拉列表而不提交按钮 - Get Selected Value of dropdown without submit button 获取没有提交按钮的下拉菜单的选定文本 - Get selected text of dropdown menu without submit button 在下拉菜单中取消激活所选值的“提交”按钮 - Deactivate the 'Submit' button for the selected value in dropdown menu 在没有提交按钮的情况下获取选定的单选按钮 - Get Selected Radio Button WITHOUT a Submit button 从下拉列表中将选定的值分配给PHP变量onchange,而无需按html表单中的“提交”按钮? - Assigning a selected value from a dropdown list to a php variable onchange, without pressing submit button in a html form? 如何从下拉列表中获取选定的值并在查询中使用它而不单击提交? - How to get the selected value from dropdown and use it in query without clicking submit? 单击提交按钮后如何保持下拉菜单的选定值 - How to remain selected value of dropdown after click on submit button 如何从数据库获取文本框中的值取决于没有提交按钮的下拉列表 - How to get the value in Textbox from database depends on dropdown list without submit button Bootstrap 5 Dropdowns:在下拉按钮中获取选定的下拉项目值 - Bootstrap 5 Dropdowns: Get selected dropdown item value in the dropdown button Flask 在没有提交按钮的情况下获取复选框值 - Flask get checkbox value without submit button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM