简体   繁体   English

如何以下拉形式添加onchange函数以发送数据?

[英]how can I add onchange function in a dropdown form to send data?

how can I send the data from a dropdown form with onchange function? 如何使用onchange函数从下拉表单发送数据?

Just like www.abc.com/index.php?version=(the value I suppose to send) 就像www.abc.com/index.php?version=(我想发送的值)

I can only use onChange to submit the data, but it is not I want. 我只能使用onChange提交数据,但这不是我想要的。

<form action="gp_data.php?gp_name=<?php echo $_GET['gp_name'] ?>&version=<?php echo $_POST['version'] ?>" method="POST">

<select name="version" onChange="this.form.submit()">

<option>Vers</option>

<?php while($subjectData = mysql_fetch_array($version)){ ?>

<option value="<?php echo $subjectData['version'];?>">
<?php echo $subjectData['version'];?>

</option>

<?php }?> 

</select>

</form>

1- Form-data can be sent as URL variables (with method="get"). 1-表单数据可以作为URL变量发送(使用method =“ get”)。 GET to send sensitive data! GET发送敏感数据! (will be visible in the URL) like www.abc.com/index.php?version=value (将在URL中显示),例如www.abc.com/index.php?version=value

2- you can use hidden filed to send the store data on server. 2-您可以使用隐藏字段在服务器上发送存储数据。 that cannot be seen or modified by users when a form is submitted. 提交表单时用户无法看到或修改的内容。

<form action="index.php" method="GET">
    <!----- Get the session value -->
    <?php
    $gp_name = $_SESSION['gp_name'];
    ?>
    <!---- use the hidden file to send the session data within action ---->
    <input type="hidden" name="gp_name" value="<?php echo $gp_name;?>">

    <select name="version" onChange="this.form.submit()">

        <option>Vers</option>

        <?php while($subjectData = mysql_fetch_array($version)){ ?>

        <option value="<?php echo $subjectData['version'];?>">
        <?php echo $subjectData['version'];?>

        </option>

    <?php }?> 

    </select>

</form>

After submit the form, data will send by url like. 提交表单后,数据将通过url之类发送。

www.abc.com/index.php?gp_name=gp_name&version=Vers2

Try this 尝试这个

<form method="POST" action="">
    <select name="version" id="myselect" onchange="this.form.submit()">
        <option>Vers</option>
        <?php while($subjectData = mysql_fetch_array($version)){ ?>
        <option value="<?php echo $subjectData['version'];?>">
        <?php echo $subjectData['version'];?>
        </option>
        <?php }?> 
    </select>
</form>

This task can be simply achieved by using Jquery. 使用Jquery可以轻松完成此任务。

First of all add Jquery on your page. 首先在页面上添加Jquery。

Then call On change event in Ready state. 然后在就绪状态下调用更改事件。

$(document).ready(function(){


  $('#myselect').on('change', function(){


     //Give your form an ID, i assume it is MyForm
     $('#MyForm').submit();


  });// Change


});// Ready

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

相关问题 如何将其发送给onchange函数以进行选择? - How can I send this to an onchange function for a select? 如何对表单下拉列表的“ onchange”和“ aspx状态”信息做出反应? - How can I react to 'onchange' and 'aspx state' information for a form dropdown? 如何禁用带有 javascript onchange 功能的表单? - How can I disable a form with javascript onchange function? 如何将元素添加到使用 onchange 事件调用函数的数组中? - How can I add element to an array calling a function with the onchange event? 如何将 onChange 添加到我的 onClick function? - How can I add onChange to my onClick function? 如何设置数据是否清除 onChange function 不执行 - how can I set if data get clear onChange function not execute 如何使用第一个下拉列表中的onChange事件填充另一个下拉列表? - How can I populate another dropdown with the onChange event of the first dropdown? 如何使用下拉菜单调用 jQuery function 以便下拉菜单的 onChange 将刷新 div,而不仅仅是将 function 结果添加到其中? - How to call a jQuery function with a dropdown so that the dropdown's onChange will refresh the div, not just add the function result to it? 如何以编程方式触发选择下拉式onchange事件? - How can I fire select dropdown onchange event programatically? 如何为所有HTML表单字段添加onChange函数 - How to add onChange function for all HTML form fields
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM