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
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()
You also have another problem. The hidden input is generating a new input every single time you select a region prior to clicking search.
<li class="field">
<input class="input" type="text" autocomplete="off" placeholder="Write a summoner name" name="summonerName" id="summonerName">
<a onclick="$('#form').submit();"><i class="icon-search" style="top: -9%;"></i></a>
</li>
<input type="hidden" class="hiddenRegion" name="hiddenRegion" style="display: none;"></input>
<input type="hidden" class="hiddenRegion" name="hiddenRegion" style="display: none;"></input>
<input type="hidden" class="hiddenRegion" name="hiddenRegion" style="display: none;"></input>
Input tags never have </input>
at the end, and you get and set its value in JavaScript using the .value
property, or in JQuery the .val
method.
So, this should fix your problem:
$('.Value').click(function(e){
var value = $(e.target).text();
$('.hiddenRegion').val(value);
});