I'm modifying a shopping cart. On the product input page I added two fields($vendor
& $percentup
) just above the price field. The idea is that the vendor price times the percentage creates the retail price(Price = vendorprice * percentage)
. I also want to leave the retail price field to enter a price manually. All information gets added to MySQL.
I have this code at the top of the page to do the math:
<?php $price_update=( (($vendor*$percentup)/100) + $vendor )?>
<?php if ($price_update > $price) $price=$price_update ?>
Right now I have to submit the page
<a onclick="$('#form').submit();" class="button">
And then go back to the page for the values to update, then submit a 2nd time for the change to the Price field to be reflected.
From what I have read about AJAX, this sounds like a function that AJAX was built for, but I have no idea how to do it.
Is there some easy code that does the above while removing all those steps?
Try using jQuery, it's easier for getting things done faster: http://api.jquery.com/category/ajax/
And maybe you'll want to take a look at .post()
and .load()
jQuery methods also, as they will most probably suit your needs, as they have an fast learning curve.
OTOH, I highly recommend learning the library-independent way of handling AJAX calls, since this is precious knowledge of "how web works" and can save you from using more stuff than you need. Follow this simple tutorial, for example: