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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:13:03+00:00 2026-06-07T23:13:03+00:00

I have used this website a lot for research etc and find it extremely

  • 0

I have used this website a lot for research etc and find it extremely useful.

I have been developing a little bit of code that will get a list of input id names and then add there values together using javascript/jquery.

This is what I have so far – it might be well off the mark as I am still a novice.

So far the code gets the names of the inputs fine. It also does the calculation fine but when I put the array into the “var fieldnames” the calculation stops working?

When I copy the array out (after putting it into an input) and pasting it into the “var fieldnames” it works fine.

The issue seems to be that the array doesnt pass over to the “var fieldnames” correctly??

Here is the code from the page – it puts the array into the inputs at the bottom for investigation purposes only but the calculation doesnt work unless you put the input names in manually!

Any help would be much appreciated.
Thanks

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
</head><body>




<script type="text/javascript" language="javascript">
function getTotal(oForm)
  {
var arrayOfIDs = $('.myClass').map(function() { return this.id; }).get();
var test = (arrayOfIDs.length ? "'" + arrayOfIDs.join("','") + "'" : "");

 document.getElementById("sum").value = test;

  var field, i = 0, total = 0, els = oForm.elements;
  var fieldnames = [test];

  document.getElementById("sum1").value = fieldnames;

  for (i; i < fieldnames.length; ++i)
  {
  field = els[fieldnames[i]];
  if (field.value != '' && isNaN(field.value))
  {
  alert('Please enter a valid number here.')
  field.focus();
  field.select();
  return '';
  }
  else total += Number(field.value);
  }
  return ' ' + total;
  }
</script>




<div id="listing">
<form>
<table>
<td>8065020</td>
<td>2012-04-10</td>
<td>household</td>
<td><input    class="myClass" id="pay47" type="text" name="pay47" value="38.45"/></td>
</tr>
<tr>
<td>8065021</td>
<td>2012-04-10</td>

<td>household</td>
<td><input   class="myClass" id="pay48" type="text" name="pay48" value="37.4"/></td>
</tr>
<tr>
<td>8065022</td>
<td>2012-04-10</td>
<td>household</td>
<td><input   class="myClass"  id="pay49" type="text" name="pay49" value="375"/></td>
</tr>
<tr>
<td>8065014</td>
<td>2012-04-04</td>

<td>household</td>
<td><input type="text"  class="myClass"  id="pay50" name="pay50" value="06"/></td>
</tr>
<tr>
<td>8065015</td>
<td>2012-04-04</td>
<td>motorprotect</td>
<td><input type="text"  class="myClass"  id="pay51" name="pay51" value="01"/></td>
</tr>
<tr>
<td>8065011</td>
<td>2012-03-06</td>

<td>household</td>
<td><input type="text"   class="myClass" id="pay52" name="pay52" value="55"/></td>
</tr>
<tr>
<td>8065012</td>
<td>2012-03-06</td>
<td>household</td>
<td><input type="text"  class="myClass"  id="pay53" name="pay53" value="56"/></td>
</tr>
<tr>
<td>1</td>
<td/>

<td>household</td>
<td><input type="text"   class="myClass" id="pay54" name="pay54" value="56"/></td>
</tr>
<tr>
<td>2</td>
<td/>
<td>household</td>
<td><input type="text"  class="myClass"  id="pay55" name="pay55" value="52"/></td>
</tr>
<tr>
<td>3</td>
<td/>
<td>household</td>

<td><input type="text"  class="myClass"  id="pay56" name="pay56" value="53"/></td>
</tr>
<tr>
<td>4</td>
<td/>
<td>household</td>
<td><input type="text"  class="myClass"  id="pay57" name="pay57" value="55"/></td>
</tr>
<tr>
<td>8065001</td>
<td/>
<td>landlord</td>
<td><input type="text"  class="myClass"  id="pay58" name="pay58" value="5"/></td>

</tr>
<tr>
<td>8065002</td>
<td/>
<td>landlord-basic</td>
<td><input type="text"   class="myClass" id="pay59" name="pay59" value="59"/></td>
</tr>
<tr>
<td>8065003</td>
<td/>
<td>household</td>
<td><input type="text"  class="myClass"  id="pay60" name="pay60" value="5"/></td>
</tr>

<tr>
<td>8065004</td>
<td/>
<td>household</td>
<td><input type="text"  class="myClass"  id="pay61" name="pay61" value="5"/></td>
</tr>
<tr>
<td>8065005</td>
<td/>
<td>household</td>
<td><input type="text"   class="myClass" id="pay62" name="pay62" value="5"/></td>
</tr>
<tr>

<td>8065006</td>
<td/>
<td>landlord-basic</td>
<td><input type="text"   class="myClass"  id="pay63" name="pay63" value="64"/></td>
</tr>
<tr>
<td>8065008</td>
<td/>
<td>household</td>
<td><input type="text"   class="myClass" id="pay64" name="pay64" value="5" /></td>
</tr>
<tr>
<td>8065010</td>

<td/>
<td>business-basic</td>
<td><input type="text"  class="myClass"  id="pay65" name="pay65" value="10" /></td>
</tr>
</table>


<input id="total" type="text" name="total" value="" readonly="readonly" /> 
<input type="button" value="Get Total" onclick="total.value=getTotal(this.form)" />
<br /><br />
<input name="totalpay" id="sum" type="text" />sum<br />
<input name="totalpay" id="sum1" type="text" />sum1
</form>
</div>






</body>
</html>
  • 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-06-07T23:13:06+00:00Added an answer on June 7, 2026 at 11:13 pm

    1- Replace the line

    var test = (arrayOfIDs.length ? "'" + arrayOfIDs.join("','") + "'" : "");
    

    By

    var test = (arrayOfIDs.length ? arrayOfIDs.join(",") : "");
    

    2- Replace

    var fieldnames = [test];
    

    By

    var fieldnames = test.split(",");
    

    3- Replace

    field = els[fieldnames[i]];
    

    By

    field = document.getElementById(fieldnames[i]);
    

    What i did here is only correct you code to resolve your problem, but i am covinced that you can do this in a more easiest way.

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

Sidebar

Related Questions

I have used this website for testing http://www.webpagetest.org and among some suggestions for optimization
I've used this code to have a like btn on my site: <iframe src=http://www.facebook.com/plugins/like.php?href=URL_OF_YOUR_WEBSITE&amp;send=false&amp;layout=standard&amp;width=450&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font&amp;height=80&amp
I have used this code (kind of tutorial) at http://code.google.com/p/gwt-examples/wiki/gwt_hmtl5 ... In this code,
I have used this custom grid view in my code, and I want to
I have used this code for extracting urls from web page.But in the line
I have used this forum for a while now to find answers to some
I already did a lot of research on this topic and have implemented a
I've been doing a lot of research trying to find the best way to
I have created web-site using Joomla 2.5. In this website, I have used registration.
i have used this: Margins margins = new Margins(5, 5, 5, 5); printForm1.PrinterSettings.DefaultPageSettings.Margins =

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.