I have a text box and dropdown list box. In dropdown list box i'm having the list of equipments which are having the different price according to the equipment. User take the equipment for the rent for the num of days. Now I calculate the price for the rent using php function.
Now all I want is, to display that respected calculated value at the text box while clicking the respective item in a dropdown list box by calling that function in the html form using php.
Could anyone help me to fix this problem with the example?
Haven't tested it, and since you didn't give any more information, this is based on a php as source file which echo's the price, when called with 2 parameters:
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
$("#items").change(function() {
$.ajax({
url: "http://url/data.php",
data: {
selectedItem: $("#items").val(),
days: $("#days").val()
},
success: function() {
$("#total").html(data)
}
}
}
</script>
</head>
<body>
<form>
<input id="days" value="1" />
<select id="items">
<option value="1">Object 1</option>
<option value="2">Object 2</option>
</select>
Calculated costs: <span id="total"></span>
</form>
</body>