开发者

how to pass the id value of a select list in a form using post or get?

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>

And here is the simple print php code:

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

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!


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>                


ID's won't get passed automatically in HTTP.

You need either:

  1. Use an input hidden
  2. Use a special name. I.E. <select name="select_1" id="1">...</select
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜