Answer the question
In order to leave comments, you need to log in
How to get select value by ajax in PHP file?
Good afternoon, I can not figure out how to get the select value in the php file and send it back
div id="message"></div>
<select id="select">
<option value="black">Черный</option>
<option value="white">Белый</option>
<option value="red">Красный</option>
</select>
$(document).ready(function ()
{
$('#select').on('change', function ()
{
if ($('#select').val() === null) {
alert("Error");
}
else
{
var selectedValue = $('#select').val();
$.ajax
({
url: 'index.php',
type: 'POST',
data: 'espace_id=' + selectedValue,
success: function(data)
{
$('#message').html(selectedValue);
}
});
}
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question