After unsuccessfully attempting to solve my issue strictly with Ajax, I have made the move to JQuery. Unfortunately I have a limited understanding of JQuery and was hoping someone could tell me what it is I am doing wrong. I have spent multiple days on this problem and have essentially got nowhere!

My task in theory is simple, all I want to do is take the value of a HTML drop down menu and call a php function with the appropriate row of the drop down menu. The php function print_wp_cart_button_for_product outputs an add to cart button. The function is to be called via a row that corresponds to an item in my product array.

<TR>
   <TD>
   <select id="productcategory1" name="productcategory1" onchange="productchange()">
    <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>

  <script type = "text/javascript">
  function productchange() 
  {
      var currentrow = $('#productcategory1').val();
      //alert(currentrow);

      $.ajax({
        type: "GET",
        url: "http://www.example.com/wp-content/themes/themeX/order.php",
        data: "rownum=" + currentrow,
        success: function(currentrow){
            $("#test").html(currentrow);
            }});
      return false;
  }
  </script>

  <?php $rownum = $_GET['test']; ?>
  <?php echo print_wp_cart_button_for_product($products[$rownum]["Product"], $products[$rownum]["Price"]); ?>
  </TD>
  </TR>  

Order.php:

<?php
$rownum = $_GET['rownum'];
echo "Row Number = $rownum";
?>
share|improve this question
feedback

1 Answer

$.ajax({
        type: "GET",
        url: "http://www.example.com/wp-content/themes/themeX/order.php",
         data: {'rownum': currentrow},
        success: function(currentrow){
            $("#test").html(currentrow);
            }});

Try that. Also

<?php $rownum = $_GET['test']; ?>

You dint close the last php and started another..that gives error in first place

Everything is fine in your codes..as far as i see. Have you included jquery library file??

share|improve this answer
Unfortunately, that didn't appear to change anything. – panoramic Dec 28 '12 at 19:00
i can see no other problem in ur jquery code – I-love-php Dec 28 '12 at 19:03
Would the issue be with the order.php file or the manner in which I am calling the print_wp_cart_button_for_product in that case? – panoramic Dec 28 '12 at 19:07
I had the second to last php closed in code, but must have missed it when i copied it over to make the post. I don't receive any errors, but nothing happens when I change my selection with the dropdown menu. However I know the function is being called when I uncomment out the alert. – panoramic Dec 28 '12 at 19:19
did u add jquery library file??? – I-love-php Dec 28 '12 at 19:23
show 9 more comments
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.