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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:29:44+00:00 2026-05-17T17:29:44+00:00

I have been trying to solve this for a while. I am trying to

  • 0

I have been trying to solve this for a while. I am trying to get value of a form input which is inside a nested loop. But its coming undefined. Any idea why so? Thanks much for your help in advance. Here is the code for example.

I am getting the value of $(#fund-no-"+f).attr('value') without any problem. Its $("#year-" + year_amt + "-" + f).attr('value') that i cant retrieve. It comes undefined. If i use $("#year-" + year_amt + "-" + f).val() instead i dont get any value at all.

 var fund_datastring;
 fund_datastring = "";
 if(fundqty >0)
 { 
  for(var f =1; f <= fundqty; f++)
  {
   fund_datastring += "&fund_no_" + f + "=" + $("#fund-no-" + f).attr('value') ;  

     var fundyear_datastring = "";
     var hidden_fundid = $("#hidden-fund-id-"+f).attr('value');

   var year_amt=2;
   //for(var year_amt =2; year_amt < hidden_fundid; year_amt++)
   while (year_amt < hidden_fundid)
   {
    fundyear_datastring += "&hidden_fund_"+f+ "=" + hidden_fundid + "&fund_"+ f +"_amount_"+ year_amt + "=" + $("#year-" + year_amt + "-" + f).attr('value') + "&fund_"+ f +"_year_"+ year_amt + "=" + year_amt;

   year_amt++
   }
   hidden_fundid = "";


  }


 }


<div class="fsFieldHorizontal"> 
    <input type="text" value="" class="fsField" size="32" name="year_1_1" id="year-1-1"> 
    <input type="hidden" value="4" id="hidden-fund-id-1"> 
        <a onclick="addFundForm(this); return false;" id="add-year-1" href="#"> 
            <img alt="Add Year" src="images/add_16.png"> 
        </a><br><br> 
        <div id="year-container-1"> 
            <div id="year-2-1" style="margin: 5px 0px;">
                <input type="text" value="" class="fsField" size="32" name="year_2_1" id="year-2-1">
                    <a onclick="removeFundYear("#year-2-1"); return false;" href="#">
                        <img alt="Remove Year 2" src="images/cancel_16.png">
                    </a><br>
                    <label for="year-2-1" class="fsSupporting">Year 2 Amount</label>
            </div>
            <div id="year-3-1" style="margin: 5px 0px;">
                <input type="text" value="" class="fsField" size="32" name="year_3_1" id="year-3-1">
                    <a onclick="removeFundYear("#year-3-1"); return false;" href="#">
                        <img alt="Remove Year 3" src="images/cancel_16.png">
                    </a><br>
                    <label for="year-3-1" class="fsSupporting">Year 3 Amount</label>
            </div>
        </div> 
</div>
  • 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-17T17:29:44+00:00Added an answer on May 17, 2026 at 5:29 pm

    Update 2

    As I suspected below, your IDs were not unique: You have both this:

    <div id="year-2-1" style="margin: 5px 0px;">
    

    And this:

    <input type="text" value="" class="fsField" size="32" name="year_2_1" id="year-2-1">
    

    jQuery is probably finding the first one, which does not (of course) have a value.

    Update 1

    From what you’re describing, the most likely scenario is that you don’t have an element with the ID year-2-1 (on the first pass) and so on — or you have more than one such element (which is invalid and so unpredictable). Because fundamentally, if the DOM is right, it works: http://jsbin.com/icume3 And if there’s no element with that ID, you get exactly what you’re describing: http://jsbin.com/icume3/2

    Old, apparently incorrect answer (in more ways than one):

    You haven’t shown your markup, but my guess would be that .val() is working where .attr("value") is not because you’re dealing with a form element that doesn’t have a value attribute, like a select (see below). .val gets the value of the element, which varies depending on what kind of element it is.

    Edit: Apparently jQuery handles “value” in attr, at least for selects, at least on the browsers I tried (including IE6, so): http://jsbin.com/oxega3 So not that.

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

Sidebar

Related Questions

I have been trying to create a simple application that will let the user
I've been plowing through tutorials all day trying to install RMagick, and have gotten
The html / CSS I've been using is below. When the cursor is over
I have an odd problem that I just can't seem to diagnose, and it
I am currently trying to integrate a live search functionality in android. I use
This is my fist stackoverflow post so please be gentle with me! I'm sure
I have a C++ application that loads lots of data from a database, then
Can you please help me to solve the following problem. I am running a
I'm reading Cracking the Coding Interview, Fourth Edition: 150 Programming Interview Questions and Solutions

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.