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 4587474
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:47:09+00:00 2026-05-21T21:47:09+00:00

I can read out text field values, but when I try to find the

  • 0

I can read out text field values, but when I try to find the selected radio button, I get nothing.

$(document).ready(function(){

    $("form#create_form").submit(function() {

    var title      = $('#title').attr('value');
    var owner      = $('#owner').attr('value');
    var users      = $('#users').attr('value');
    var groups     = $('#groups').attr('value');
    var begin_date = $('#begin_date').attr('value');
    var end_date   = $('#end_date').attr('value');

    // get selected radio button 
    var type = '';
    for (i=0; i<document.forms[0].type.length; i++) {
        if (document.forms[0].type[i].checked) {
        type = document.forms[0].type[i].value;
        }
    }

HTML:

<div class="create-new">
  <form id="create_form" name="create_form" action="" method="post">
  ...
  <input name="type" id="type" value="individuel" type="radio" /> Individuel <br/>
  <input name="type" id="type" value="course"     type="radio" /> Course <br/>

  <button class="n" type="submit">Create</button>
  </form>

What am I doing wrong?

  • 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-21T21:47:10+00:00Added an answer on May 21, 2026 at 9:47 pm

    I would suggest an alternative method to getting the selected radio button (since you are already using jQuery):

    $('input:radio[name=type]:checked').val();
    

    This solution is an example on .val().

    The above solution is much more succinct, and you avoid any conflicts in the future if other forms are added (i.e you can avoid the potentially hazardous document.forms[0]).

    Update

    I tested your original function with the following fiddle and it works:

    http://jsfiddle.net/nujh2/

    The only change I made was adding a var in front of the loop variable i.

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

Sidebar

Related Questions

I am wondering how I can read CSS comments out of a linked stylesheet.
I can read the MySQL documentation and it's pretty clear. But, how does one
How you can read a file (text or binary) from a batch file? There
The Adobe docs (I can't find which) state that Flash can read Shared Objects
I just can't figure out how to upload images in django. I've read dozens
I am using the following Javascript to read strings out of a text file
I'm trying to read specific values from the text file (below): Current Online Users:
Anyone can read the GoF book to learn what design patterns are and how
You can read about the 64-bit calling convention here . x64 functions are supposed
In .Net you can read a string value into another data type using either

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.