简体   繁体   中英

how do i add the value from radio button for adding addcart

iam working with my new project.my question is how do i add the values from radio button for addcart. that is when i click the radio buttons that should add with addcart amount.i have a multiple radio buttons with differnt values any one say how?

after this step what should i use javascript or ajax. i tried but that value did not add with previous value thanks in advance regards keils

since you have tagged this as jquery im assuming you are using jquery. the way to select the value will be as follows

$('input:radio[name=<name of your radio buttons>]:checked').attr("value");

and if you want to bind events on the radio buttons on page load you need to do something as follows

$('input:radio[name=<name of your radio buttons>]').each(
$(this).change(function()
{
$('#<id of text box u want to update>').val($('#<id of text box u want to
 update>').val()+$(this).attr("value"));
//your ajax code goes here: $.ajax(url,itemValue:$(this).attr("value")),success:success...
})
)

Note: I'm assuming that your value is stored in a text box you can have anyother kind of element there.

Well If you want to update your code on the server too then yea you need to send an ajax request within that function to your server side handler and process it there. Here is wat u need to use in that case: http://api.jquery.com/jQuery.ajax/

Hope that helps

<form name ="form1" method ="post" action ="radioButton.php">

<Input type = 'Radio' Name ='option_radio1' value= '6'>Size 6
<Input type = 'Radio' Name ='option_radio2' value= '5'>Size 5
<Input type = 'Radio' Name ='option_radio3' value= '4'>Size 4
<Input type = "Submit" Name = "Submit1">
</form>

<?PHP
$pro_option1 = $_POST['option_radio1'];//get the radio button values using name
$pro_option2 = $_POST['option_radio2'];
$pro_option3 = $_POST['option_radio3'];
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM