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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:43:13+00:00 2026-05-26T06:43:13+00:00

I’m using this customInput plugin (with jQuery 1.6.2) to customize the look of my

  • 0

I’m using this customInput plugin (with jQuery 1.6.2) to customize the look of my radio buttons.

It works great.

The problem I have now is that I’m just trying to get the index() number of the selected radio button and it always returns 0. There are six radio buttons and I’m looking for a number between 0 and 5.

JavaScript:

$('input[name="amount"]').click(function() {
    var x = $(this).filter(':checked').index();
    var y = $(this).filter(':checked').val(); //<-- for troubleshooting
    alert(x + y);  //<-- for troubleshooting
});

Oddly, val() is still working fine and returns the proper value. Therefore, the form data is always getting the correct radio value.

http://jsfiddle.net/sparky672/LdVGD/

HTML:

<fieldset id="radioset">
    <input type="radio" id="radio-1" name="amount" value="Option 1" checked="checked" /><label for="radio-1" title="">Option 1</label>
    <input type="radio" id="radio-2" name="amount" value="Option 2" /><label for="radio-2" title="">Option 2</label>
    <input type="radio" id="radio-3" name="amount" value="Option 3" /><label for="radio-3" title="">Option 3</label>
    <input type="radio" id="radio-4" name="amount" value="Option 4" /><label for="radio-4" title="">Option 4</label>
    <input type="radio" id="radio-5" name="amount" value="Option 5" /><label for="radio-5" title="">Option 5</label>
    <input type="radio" id="radio-6" name="amount" value="Option 6" /><label for="radio-6" title="">Option 6</label>
</fieldset>

When simply not using the customInput plugin, the index number is then returned.

http://jsfiddle.net/sparky672/LdVGD/1/


Side Question:

After disabling the plugin, the index() returns 0, 2, 4, 6, 8, or 10. It’s like the <label> itself is being counted at part of the index(), effectively doubling the count. Why should this be?

I cannot remove the <label> elements as the plugin depends on these to function.

I just want to retrieve a number from 0 to 5 depending on whether radio button 0 through 5 is checked.

Any suggestions? Perhaps another method to check which radio button is selected?

My ultimate goal? To simply change some variables depending on which button is selected.

  • 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-26T06:43:13+00:00Added an answer on May 26, 2026 at 6:43 am

    As you’ve noticed, your index call doesn’t quite work the way you expect it to when you don’t use the plugin. From the fine manual:

    If no argument is passed to the .index() method, the return value is an integer indicating the position of the first element within the jQuery object relative to its sibling elements.

    You’re getting values twice as large as you think they should be because the <label> elements are also siblings so you have five <input> elements and five <label> elements in the sibling list.

    When you activate the plugin, your radio buttons get wrapped in a <div> so the structure of each button looks like this:

    <div>
        <input type="radio">
        <label>
    </div>
    

    That leaves the radio button with a single sibling, <label>, and an index of zero.

    You already have id attributes on your radio buttons so why not use those to figure out the index? Something like this:

    var index = parseInt(this.id.replace(/radio-/, ''), 10) - 1;
    

    Check the third number in these demos:

    • With plugin: http://jsfiddle.net/ambiguous/nGVkC/
    • Without plugin: http://jsfiddle.net/ambiguous/UkPh8/

    Or you could use the element form of index:

    If .index() is called on a collection of elements and a DOM element or jQuery object is passed in, .index() returns an integer indicating the position of the passed element relative to the original collection.

    So you could do it like this:

    var i = $('input[name=amount]').index(this);
    

    And some demos:

    • With plugin: http://jsfiddle.net/ambiguous/yAVHn/
    • Without plugin: http://jsfiddle.net/ambiguous/vP3Du/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.