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 read about ContactsContract.CommonDataKinds.GroupMembership , but I can't figure out what URI use to
I have read the FactoryGirl documentation, but I can't seem to figure this out.
I have read my code again and again, but I can't figure out whats
I just can't realize why my read time out is not working. All I
I can't figure out why option (1) doesn't work. I have read the live
I can read unmanaged memory in C# using UnmanagedMemoryStream, but how can I do
How I can Read the RGB-Pixel by Pixel values from CGImagea also after how
I need to read from an XML document which is alreay working. But now
I have this code, how can I get the selected value of the @htmlDropDownList
I just can't figure out how to upload images in django. I've read dozens

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.