0

I'm attempting to get the value of a radio button field via Ajax, but it returns only 'undefined'.

I'm using:

function  fetch_data(id,type)
{
    $.ajax({
            type: "POST",
            async: false,
            url: "fetch_data.php",
            data: "id="+id+"&type="+type,
            success: function(msg){
                         $("#div1").html(msg);  
                     }
    });
}

<select name="data1" id="data1"
onchange="fetch_data(this.value,document.getElementsById('radio1').value"
style=" width:150px;"> 


<div id="div1"></div>

will replace with "fetch_data.php" page div

3
  • where is the rAdio button and setting code int he above snipplet ? Commented Apr 11, 2012 at 5:48
  • <input type="radio" id="radio1" name="radio" value="1" /> <input type="radio" id="radio2" name="radio" value="2" /> Commented Apr 11, 2012 at 5:51
  • i am trying to fetch radio button value document.getElementsById('radio1').value Commented Apr 11, 2012 at 5:52

3 Answers 3

2

Check whether you have radio1 as an ID to your radio box and replace document.getElementsById with document.getElementById

Sign up to request clarification or add additional context in comments.

2 Comments

document.getElementsById('radio1').value it gives me 'undefined'
Yeah coz you should use document.getElementById('radio1').value
1

codef0rmer is right, you got an error in your syntax you wrote getElement*S*ById but it's called getElementById without the S.

Comments

0

You could try the following:

<select name="data1" id="data1" 
        onchange="fetch_data(this.value,"+document.getElementsById('radio1').value+""          
        style=" width:150px;">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.