How can I pass select field ID and its value to ajax without having any form?
Posted
by
user3766078
on Stack Overflow
See other posts from Stack Overflow
or by user3766078
Published on 2014-08-19T04:13:41Z
Indexed on
2014/08/19
4:20 UTC
Read the original article
Hit count: 111
I have a select field which has ID name as 'region_code' well as its value. And I want pass ID in ajax. As you can see below, the input field is not included in any form. It has a value and the ID
Is it possible to get value in ajax as shown below?
echo '<select id="region_code" onchange="show_region_code();">';
$result = mysql_query("SELECT region_code, region_name FROM list_region");
while($rows = mysql_fetch_array($result)) {
echo "<option value=\"$rows[0]\">".$rows["1"].'</option>';
}
echo '</select>';
My ajax function as below
function show_region_code() {
var region_code = $("#region_code").val();
$.ajax ({
type: "POST",
url: "show_region_code.php",
data: { region_code1: region_code },
success: function(data) {
$("#region_code").html(data);
}
});
}
© Stack Overflow or respective owner