从下拉框中获取所选值的下2个值

时间:2014-03-22 08:49:39

标签: php html html-select

<form action="index.php" method="post">
    <select name="imageslist" onchange='this.form.submit()' >
        <option value="0">Select One</option>
        <option value="1">Image 01</option>
        <option value="2">Image 02</option>
        <option value="3">Image 03</option>
        <option value="4">Image 04</option>
        <option value="5">Image 05</option>
        <option value="6">Image 06</option>
        <option value="7">Image 07</option>
        <option value="8">Image 08</option>
        <option value="9">Image 09</option>
        <option value="10">Image 10</option>
    </select>
    <noscript><input type="submit" value="Submit"></noscript>
</form>

在我的index.php中,我有以下

var image1 = '<img id="img_<?php echo $_POST['imageslist']; ?>" src="images/<?php echo $_POST['imageslist']; ?>.png" />';
var image2 = '<img id="img_2" src="images/2.png" />';
var image3 = '<img id="img_3" src="images/3.png" />'; 

如何获取所选项目的下两个值?

1 个答案:

答案 0 :(得分:0)

抱歉,我完全不明白你的问题

希望这可以帮助你

<script type="text/javascript">
    function test(a)
    {
        var r=document.forms['fm'].imageslist[(parseInt(a.value)+1)];
        document.getElementById('second').value=r.value;

        var r2=document.forms['fm'].imageslist[(parseInt(a.value)+2)]; 
        document.getElementById('third').value=r2.value;
    }
</script>

<form action="index.php" method="post" name='fm'>
    <select name="myList" onchange='test(this)' >
        <option value="0">Select One</option>
        <option value="1">Image 01</option>
        <option value="2">Image 02</option>
        <option value="3">Image 03</option>
        <option value="4">Image 04</option>
        <option value="5">Image 05</option>
        <option value="6">Image 06</option>
        <option value="7">Image 07</option>
        <option value="8">Image 08</option>
        <option value="9">Image 09</option>
        <option value="10">Image 10</option>
    </select>
    <input type="submit" value="Submit">
    <input type="hidden" name="second" id="second">
    <input type="hidden" name="third" id="third">
</form>

in index.php 

print_r($_POST);// Array ( [myList] => 4 [second] => 5 [third] => 6 )