Following below code output value input text box using ajx, php
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
function get_id_val(val){
var option = val.options[val.selectedIndex];
var hr = new XMLHttpRequest();
$.ajax({
type: "GET",
url: "sql.php",
data: "value="+option.value,
success: function(message){
// alert(message);
//$("#result").html(message);
// $('#s_op_id').val(message.s_op_id);
//$("#s_op_id").val(message.returnValue);
// body:$('#s_op_id').val()
// alert(data);
// $('#s_op_id').text(data);
// $('#s_op_id').val(data);
// document.form1.s_op_id.value = $('#s_op_id').val();
// var return_data = message;
// alert(return_data);
//document.getElementById("s_op_id").innerHTML = message;
document.form1.s_op_id.value = message;
},
failure: function() {
alert('fail');
}
});
}
</script>
<form name="form1" >
<select onchange="javascript:get_id_val(this)" id="variation_select_61_10" class="wpsc_select_variation">
<option value="0" disabled="disabled">-- Please Select --</option>
<option value="13">L</option>
<option value="12">M</option>
<option value="11">S</option>
</select>
<input type="text" name="s_op_id" id="s_op_id"/>
<!-- <div id="result">
*/result shows here /*
</div> --></form>
php code as file sql.php
<?php
echo $_REQUEST['value'];
?>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
function get_id_val(val){
var option = val.options[val.selectedIndex];
var hr = new XMLHttpRequest();
$.ajax({
type: "GET",
url: "sql.php",
data: "value="+option.value,
success: function(message){
// alert(message);
//$("#result").html(message);
// $('#s_op_id').val(message.s_op_id);
//$("#s_op_id").val(message.returnValue);
// body:$('#s_op_id').val()
// alert(data);
// $('#s_op_id').text(data);
// $('#s_op_id').val(data);
// document.form1.s_op_id.value = $('#s_op_id').val();
// var return_data = message;
// alert(return_data);
//document.getElementById("s_op_id").innerHTML = message;
document.form1.s_op_id.value = message;
},
failure: function() {
alert('fail');
}
});
}
</script>
<form name="form1" >
<select onchange="javascript:get_id_val(this)" id="variation_select_61_10" class="wpsc_select_variation">
<option value="0" disabled="disabled">-- Please Select --</option>
<option value="13">L</option>
<option value="12">M</option>
<option value="11">S</option>
</select>
<input type="text" name="s_op_id" id="s_op_id"/>
<!-- <div id="result">
*/result shows here /*
</div> --></form>
php code as file sql.php
<?php
echo $_REQUEST['value'];
?>
No comments:
Post a Comment