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

  • SEARCH
  • Home
  • 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 9171929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:13:49+00:00 2026-06-17T16:13:49+00:00

I checked for duplicates but didn’t find an exactly same problem so here we

  • 0

I checked for duplicates but didn’t find an exactly same problem so here we go. I have two radio-buttons and I need to return their values upon form submission. The problem is that when I click the submit button I always get the same radio-button value. Here is some code:

<div id="automatic">
        <p>Title1
            <input type="radio" id ="mode" name="mod" value="auto" >
        </p>           
    </div>

    <div id="selection">
        <p>Title2
            <input type="radio" id ="mode" name="mod" value="nonauto" >
        </p>           
    </div>

    <form id="search" action="test.jsp" method="GET" onsubmit="if (document.getElementById('search_text').value.length < 1) return false;">
        <input id="search_text" type="text" name="q">
        <input id="searchButton" type="submit" onclick="displayRadio()" value="Search" autocomplete="off" size="115">
    </form>

And here is the Javascript code:

function displayRadio() {
        alert(document.getElementById("mode").value)
}
  • 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-06-17T16:13:49+00:00Added an answer on June 17, 2026 at 4:13 pm

    Use different ids and use your function to lookup which of them is checked and return the value of that.

    function displayRadio() {
        var modeauto = document.getElementById('modeauto');
        var modenoauto = document.getElementById('modenoauto');
        var value = modeauto.checked ? modeauto.value : modenoauto.value;
        alert(value);
    }
    

    I would recommend using jQuery for simplicity though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I checked throught the existing topics. I have a fix for my problem but
I checked the documentation, but can't seem to find what I'm looking for. I
Poorly worded question, but I can't find a better way. Also, checked the 'related'
Possible Duplicate: Check of specific radio button is checked I have these 2 radio
Possible Duplicate: Google plus api for posting on wall like facebook I have checked
I checked the documentation and I couldn't find a way o renaming or copying
I checked all the topics, but i simply don't know why my script does
Possible Duplicate: Using ApplicationSettings to store Checked property for WinForms RadioButtons I have three
I have a subversion repo with directories that contain the usual source-controlled files, but
I have a form and as a result of that form I have two

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.