The following is an excerpt of html code:
<div id="prt">
<select name="selectPrt" class="span12" onchange="sta_callPRT();">
<option value="noPrt">Choose one vehicle.</option>
<option value="prt1">PRT 1</option>
<option value="prt2">PRT 2</option>
<option value="prt3">PRT 3</option>
<option value="prt4">PRT 4</option>
<option value="prt5">PRT 5</option>
</select>
<div class="row-fluid">
<div class="span6">
<div class="section">
<div class="sectionTitle">
<h3>Vehicle Info</h3>
</div>
</div>
<div id="state"><strong>State:</strong> </div>
<div id="freeSeats"><strong>freeSeats:</strong></div>
<div id="battery"><strong>battery:</strong></div>
<div id="totalDistance"><strong>totalDistance:</strong></div>
<div id="location"><strong>Location:</strong></div>
<div id="estimatedTime"><strong>estimatedTime"</strong></div>
<div id="estimatedDistance"><strong>estimatedDistance:</strong></div>
<div id="speed"><strong>speed:</strong></div>
In addition, there is the following Javascript:
function sta_callPRT(){
$.getJSON('PRTInfoGenerator.php', function(json){
$.each(json, function(key, value) {
if(key=="state") {
//$('#state').empty();
//document.getElementById("parameters").appendChild(divTag);
$('#state').append(value);
}
if(key=="freeSeats") {
$('#freeSeats').append(value);
}
if(key=="estimatedDistance"){
$('#estimatedDistance').append(value);
}
if(key=="estimatedTime"){
$('#estimatedTime').append(value);
}
if(key=="battery"){
$('#battery').append(value);
}
if(key=="speed"){
$('#speed').append(value);
}
if(key=="location"){
$.each(json.location, function(par_key, par_value) {
$('#location').append(par_key+': '+par_value+' ');
});
}
if(key=="totalDistance"){
$('#totalDistance').append(value);
}
});
});
}
I am looking to display random vehicle values in the HTML. I have PHP code that generates these random values for vehicles. When a vehicle is selected, it displays certain values. However, when a new selection is made, the new values are simply added to the existing ones. How can I remove the previous values and replace them with the new values upon a new selection?
For example, here is the result after the first selection:
State: Running
freeSeats:0
battery:95
totalDistance:8541
Location:x: -5 y: 34
estimatedTime:15
estimetedDistance:809
Speed:18
And here is the result after the second selection:
State: RunningRunning
freeSeats:04
battery:9540
totalDistance:85411848
Location:x: -5 y: 34 x: 84 y: -70
estimatedTime:15269
estimetedDistance:809513
Speed:1818