It sounds like you're looking for AJAX functionality. Luckily, jQuery has a function for AJAX calls, described at http://api.jquery.com/jQuery.ajax/.
You can then write some code as follows:
$(document).ready(function() {
$('#submitbutton').click(function() {
var pos = $('#inputid').val();
$.ajax({
url: "cart.php",
type: "POST",
data: {itemID: pos},
success: function(data) {
// Do stuff when the AJAX call returns
}
});
});
});
However, there is a flaw with this. If you're going to have multiple submit buttons on the same page, you cannot use the same ID for all of them. It is better to give all of the fields a class as follows:
<form name="addToCartForm">
<input type="hidden" class="inputid" value="'.$id.'"/>
<input type="submit" class="submitbutton" value="Add to cart"/>
</form>
Your final Javascript code will look like this:
$(document).ready(function() {
$('.submitbutton').click(function() {
var pos = $(this).parent().find('.inputid').val();
$.ajax({
url: "cart.php",
type: "POST",
data: {itemID: pos},
success: function(data) {
// Do stuff when the AJAX call returns
}
});
});
});