duanbeng8872 2016-03-18 16:10
浏览 186
已采纳

从脚本添加的输入框中获取值

Better will be if you can see it. On my website Loloid

There is input box, where user write his username. In menu is region and there user choose his region, where he plays. When he choose his region, in form is new hidden input with your region.

I have PHP file, where i save his username with $_POST, but it doesn't work for region. Here are my codes, I have no idea how to save my region with $_POST

//.Value are classes for regions   
    $('.Value').click(function(e){
        var value = $(e.target).text();
        $('.hiddenRegion').html(value);
    });

Here is HTML

<form method="post" action="lol.php" id="form">
    <ul>
        <li class="field">
            <input class="input" type="text" autocomplete="off" placeholder="Write a summoner name" name="summonerName" id="summonerName"/>
            <a id="formSubmit"><i class="icon-search"></i></a>
            <input type="hidden" name="hiddenInput" class="hiddenRegion"></input>
        </li>
    </ul>
</form>

And PHP

$region = $_POST['hiddenInput'];

When i print $region with echo, it returns just blank string

  • 写回答

3条回答 默认 最新

  • duanbanfei2875 2016-03-18 16:17
    关注

    You are setting the input control values and not html.In-order to set or get input control values one should use val()

    It should be $('.hiddenRegion').val(value);

    and not $('.hiddenRegion').html(value);

    And to get values

     $('.hiddenRegion').val()
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?