Gannicus
Gannicus

Reputation: 530

Can't post values of radio buttons using jQuery and php

I'm trying to get the selected value of two radio buttons by posting via jQuery and processing it in PHP. Here's my code:

HTML:

<input type="radio" name="purch" value="goods" checked>Goods<br>
<input type="radio" name="purch" value="services">Services

jQuery:

$("#addDoc").click(function(){
    $.post("manual.php",
    {
        invoice: $("#invoiceBox").val(),
        supplierName: $("#supplierBox").val(),
        refNo: $("#refBox").val(),
        vatReg: $("#vregBox").val(),
        vatPurch: $('input[name=purch]:checked', '#addForm').val()
    },
    function(data){
      alert(data);
    });
});

PHP:

<?php
    $vatPurch = $_POST['vatPurch'];

    echo $vatPurch;
?>

However I try to post it, I always get an 'Notice: Undefined index: vatPurch' error when submitting the form.

Upvotes: 0

Views: 111

Answers (1)

Bellash
Bellash

Reputation: 8184

You are using 'vatPurch' instead of 'purch'

Give a try to this and (I hope) it will work

<?php
    $vatPurch = $_POST['purch'];
    echo $vatPurch;
?>

Upvotes: 1

Related Questions