I am trying to add checkboxes dynamically with the help of javascript. However my java-script only replaces the earlier element. I need to add the newly selected element to the existing list. Here is the code. Please help.
This is index.php
<html>
<head>
<script>
function select_item(item,price)
{
if (item.length==0 || price.length==0 )
{
document.getElementById("order").innerHTML="";
return;
}
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("order").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","order.php?item="+item+"&price="+price,true);
xmlhttp.send();
}
</script>
</head>
<div id="order"></div>
</html>
<?php
echo "<a href=\"#\" onClick = \"select_item('Value1','Price1'); return false;\">Some Item1 here</a>";
echo "<br>";
echo "<a href=\"#\" onClick = \"select_item('Value2','Price2'); return false;\">Some Item2 here</a>";
?>
And this is order.php
<?php
$item=$_GET["item"];
echo "<form action=\"#\">";
echo "<input type=\"checkbox\" checked=\"yes\" name=\"vehicle\" value=\"Bike\">$item<br>";
echo "</form>";
?>
you might use this:
and
and order.php