Admittedly I am completely clueless when it comes to Ajax, but it appears the best way to accomplish my task. After going through several tutorials, I have a basic understanding, but remain lost in regards to my problem. Essentially I am attempting to capture the value of an HTML dropdown menu and call a shopping cart function with the user selected row value. Each row value corresponds to a product in a php arrray.
Function appearing in my header file (Note: The commented out portion is a failed attempt using the onreadystatechange):
<script type="text/javascript">
function productchange(data){
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
//xmlhttp.onreadystatechange=function()
//{
//if (xmlhttp.readyState==4 && xmlhttp.status==200)
// {
//document.getElementById("test").innerHTML=xmlhttp.responseText;
//document.getElementById("test").innerHTML= data;
// }
//}
var URL = "http://www.example.com/wp-content/themes/themeX/order.php" + "?rownum=" + data;
xmlhttp.open("GET",URL,false);
xmlhttp.send();
}
//-->
</script>
HTML Table: (Once again the div tags are a failed attempt using innerHTML. I was able to get the value on the screen, but still not able to capture it with $_GET to use in my function call)
<TR>
<TD>
<select id="productcategory1" name="productcategory1" onchange="productchange(this.value)">
<option value="$">--Please Select--</option>
<option value="1">Product # 1 - $1.99</option>
<option value="2">Product # 2 - $1.99</option>
<option value="3">Product # 3 - $9.99</option>
<option value="4">Product # 4 - $9.99</option>
</select>
</TD>
<TD>
<div id="test">
</div>
<?php echo print_wp_cart_button_for_product($products[$rownum]["Product"], $products[$rownum]["Price"]); ?>
</TD>
</TR>
Order.php:
<?php
global var $rownum;
$rownum = $_GET['rownum'];
?>