i have a code and i do not know what is my problem with it. i am trying to open another select from other select,and get the old select value in the new select option, but i can not do that and i do not know why. this is my code, and my page i wrote the code in it called mekha.php :
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript">
function showUser(str) {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("makhfe").style.display = "block";
}
}
xmlhttp.open("GET","mekha.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<?php
if(isset($_GET["q"]))
{
echo $_GET["q"];
}
?>
<select id="firstselect" onchange="showUser(this.value)">
<option value="1">One</option>
<option value="2">Two</option>
</select>
<select style="display:none;" id="makhfe">
<option value="1">One</option>
<option value="2"><?=intval($_GET["q"])?></option>
</select>
</body>
</html>
any help please?
Something like this should work:
$("#firstselect").change(function() {
value = $("#firstselect").val();
data = {"value": value };
$.post("server_ajax_link.php", data)
.done(function(data) {
new_data = data.new_value_from_server;
});
$("#makhfe").show();
$("#makhfe[value='2']").text(new_data );
});
For more simple examples you could check out the documentation here : http://api.jquery.com/jquery.post/