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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:34:18+00:00 2026-05-11T14:34:18+00:00

I am trying to get the index of an element using jQuery to send

  • 0

I am trying to get the index of an element using jQuery to send to a PHP script.

Here is my XHTML

<form action='/accreditation/questions/' method='post' id='questions-form'>   <fieldset id='question-0'>     <legend>Question</legend>     <h3>What colour is grass?</h3>         <ul>       <li>         <input type='radio' name='answer[0]' value='0' id='radio-0-0' />         <label for='radio-0-0'>Green</label>       </li>       <li>         <input type='radio' name='answer[0]' value='1' id='radio-0-1' />         <label for='radio-0-1'>Red</label>       </li>       <li>         <input type='radio' name='answer[0]' value='2' id='radio-0-2' />         <label for='radio-0-2'>Orange</label>       </li>     </ul>   </fieldset>   <fieldset id='question-1'>     <legend>Question</legend>     <h3>how old is alex</h3>         <ul>       <li>         <input type='radio' name='answer[1]' value='0' id='radio-1-0' />         <label for='radio-1-0'>21</label>       </li>       <li>         <input type='radio' name='answer[1]' value='1' id='radio-1-1' />         <label for='radio-1-1'>11</label>       </li>       <li>         <input type='radio' name='answer[1]' value='2' id='radio-1-2' />         <label for='radio-1-2'>23</label>       </li>     </ul>   </fieldset> </form> 

I need to get the index of the fieldset elements. I am currently using this each iterator (which I’d like not to change because it has a lot of other functions inside it).

$('#questions-form ul li').each(function() {     qIndex = $('fieldset').index($('fieldset', $(this).parent())) }); 

I’d like qIndex to be the index of fieldset relative to the form. For example, in this case I should have it equal to 0 and 1 (although there would be 6 values because it’s looping through the list elements).

I have played around for a while and have been unable to get the correct index. I keep getting not found (-1).

If it helps, here is the code I’m using to get the list item’s index relative to it’s containing ul element.

index = $('li', $(this).parent()).index(this); 

What is wrong with my fieldset index grabbing code?

  • 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. 2026-05-11T14:34:18+00:00Added an answer on May 11, 2026 at 2:34 pm

    The LI‘s parent is UL, not the fieldset.
    I think this will set qIndex for you:

    qIndex = $('fieldset').index($(this).parents('fieldset')); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to submit a form with method GET and action index.php?id=3. The
I am using the jQuery Tools Tooltip (http://flowplayer.org/tools/tooltip/index.html), and I'm trying to get the
I am trying to get index of each items in a listbox Here is
I'm trying to get a menu to slide in/out using jQuery UI and I
I am trying to get jQuery to change the html of an element and
I am trying to upload images on a form but I am using Jquery
I am trying to get the index of child of its parent. For example:-
I am trying to get the current index of the letter that typed in
I am trying to get the data for the Dow Jones Index from google.
I'm currently trying to get hold of my NSMutableArray 's index depending on one

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.