Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 581555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:35:29+00:00 2026-05-13T14:35:29+00:00

I’m going to get the checked radio button value using AJAX in PHP. I

  • 0

I’m going to get the checked radio button value using AJAX in PHP. I have done the following code, but i can’t continue.

I need your help.

ajax_radio.php

<html>
  <head>
    <script type="text/javascript" src="ajax.js" ></script>
  </head>
  <body>
    <input type="radio" name="radio1">Blue</input>
    <input type="radio" name="radio2">White</input>
    <input type="radio" name="radio3">Red</input>
    <input type="button" name="btn" value="Click" onClick="hello('a')"></input><br />
   <input type="text" id="btn_get" name="get_btn_value"></input>
  </body>
</html>

ajax.js

var xmlHttp;
function GetXmlHttpObject(){
    try{
        xmlHttp = new XMLHttpRequest();
    }
    catch(e){
        try{
            xmlHttp = new ActiveXObject(Msxml2.XMLHTTP);
        }
        catch(e){
            try{
                xmlHttp = new ActiveXObject(Microsoft.XMLHTTP);
            }
            catch(e){
                alert("doesn't support AJAX");
                return false;
            }
        }
    }
}
function hello(a){
    GetXmlHttpObject();
    xmlHttp.open("GET","ajax_radio.html?",true);
    xmlHttp.onreadystatechange = response;
    xmlHttp.send(null);
}
function response(){
    if(xmlHttp.readyState == 4){
        if(xmlHttp.status == 200){
            var radio_text = xmlHttp.responseText;
            document.getElementById('btn_get').innerHTML = radio_text;
        }
    }
}

Do you know how to complete this? Thanks in advance. 🙂

Edit:

I can’t post the code here right now, because of the low speed of network. I’m sorry.

I have shared it in rapidshare. Can you download it firstly, and help then? Thanks a lot.

I have to update it when i go back home. Too bad.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:35:30+00:00Added an answer on May 13, 2026 at 2:35 pm

    because I mostly use Jquery I wrote here a jquery snipped that checks radio button values because it is much easier and cleaner:

    <script src="http://www.google.com/jsapi"></script>
    <script>
        google.load("jquery", "1.4.0");
    </script>
    <script type="text/javascript">
        $(function() {
            $('#buttoncheck').click(function () {
                var var_name = $("input[name='radio1']:checked").val();
                $('#btn_get').val(var_name);
            });
        });
    </script>
    <html>
        <head>
            <script type="text/javascript" src="ajax.js" ></script>
        </head>
        <body>
            <input type="radio" value="Blue" name="radio1">Blue</input>
            <input type="radio" value="White" name="radio1">White</input>
            <input type="radio" value="Red" name="radio1">Red</input>
            <input id="buttoncheck" type="button" name="btn" value="Click"></input>
            <br />
            <input type="text" id="btn_get" name="get_btn_value"></input>
        </body>
    </html>
    

    Take a look for jquery here: Jquery

    Explanation:
    This part selects the item with the ID #buttoncheck and checks if its ran: $('#buttoncheck').click(function () {

    Then it will run the code in the function. This code gets the value of a input box with the name radio1. the ‘:checked’ makes sure that it only selects the value of the checked radio button:

    var var_name = $("input[name='radio1']:checked").val(); 
    

    And last. This puts the value of the variable into the item with #btn_get as id:

    $('#btn_get').val(var_name);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 447k
  • Answers 447k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You are right WebClient does not support this. You can… May 15, 2026 at 7:36 pm
  • Editorial Team
    Editorial Team added an answer You might find Suffix Trees useful (they are similar in… May 15, 2026 at 7:36 pm
  • Editorial Team
    Editorial Team added an answer You can't ask Visual Studio to build .ild files in… May 15, 2026 at 7:36 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.