如何使用post或get在表单中传递选择列表的ID值? [英] how to pass the id value of a select list in a form using post or get?

查看:106
本文介绍了如何使用post或get在表单中传递选择列表的ID值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

表单中的选择列表,我知道使用post或get传递选项值没有问题.但是,如果我也想传递选择ID值,是否可能以及如何进行?例如:

A select list in a form, I know there's no problem to pass the option value using post or get. But if I also want to pass the select id value, is it possible and how? For example:

<form action="Test.php" method="POST">
                <select name="select" id = '1'>
                    <option value="">Select a Status</option>
                    <option value="0">0</option>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                </select>                
                <input type="submit" value="submit"/>
            </form>

这是简单的打印php代码:

And here is the simple print php code:

<?php
    print_r($_POST['select']);
?>

它可以打印已选择的选项的值,但是如果我也想发布id值(此处为1),如何修改代码.我想要这样做是因为我希望id成为一个变量来存储一些int数.谢谢!

It can print the value of the option that has been chosen, but how to modify the code if I also want to post the id value, which is 1 here. I want to do so because I want the id to become a variable to store some int numbers. Thank you!

推荐答案

id属性仅设计用于客户端代码.如果您想传递额外的数据,请使用隐藏的输入-这就是它们的设计目的.

The id attribute is designed purely for use in client side code. If you want to pass extra data, then use hidden inputs — that is what they are designed for.

<input type="hidden" name="select_extra" value="1">
<select name="select">
    <option value="">Select a Status</option>
    <option value="0">0</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
</select>                

这篇关于如何使用post或get在表单中传递选择列表的ID值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆