I now am working with my project. I have the problem with the data. I have knowledge on jquery
$(document).ready(function(){
$("input[type='radio']").click(function(){
var price = $(this).val();
add_payment_value(price);
});
});
function add_payment_value(price){
// here you can use $.ajax function to add y开发者_JS百科our 'price value' to your cart
$.ajax({
type: "POST",
url: "add_payment.php",
// file where you can add price to your database
data: "",
success: function(){} // return something on success
});
}
I have 4 values which is stored in radio buttons ordered 4, 6.5, 8, 11
. My question is how to write the values in data and var price = $(this).val();
? Can anyone fill this? I gave some value but that is not working.
Change the add_payment_value function to accept a name and then uaw the code below:
$(document).ready(function(){
$("input[type='radio']").click(function(){
var price = $(this).attr("value");
var name = $(this).attr("name");
add_payment_value(price, name);
});
});
function add_payment_value(price, name){
// here you can use $.ajax function to add your 'price value' to your cart
$.ajax({
type: "POST",
url: "add_payment.php", // file where you can add price to your database
data: name + "=" + price,
success: function(){} // return something on success
});
}
Another alternative is to format the data string in the click handler and send it to add_payment_value function
$(document).ready(function(){
$("input[type='radio']").click(function(){
var price = $(this).attr("value");
var name = $(this).attr("name");
add_payment_value(name + "=" + price);
});
});
function add_payment_value(priceData){
// here you can use $.ajax function to add your 'price value' to your cart
$.ajax({
type: "POST",
url: "add_payment.php", // file where you can add price to your database
data: priceData,
success: function(){} // return something on success
});
}
use radio button id like ("#rb1").value instead of this.
精彩评论