Subtracting Values In A For Loop?

Dec 7, 2011

I am having difficulty with creating a function that uses a For Loop to pull in two unknown variables and subtracting the first number from the second number. The subtraction occurs but I always get a negative number. This exact same function works correctly when adding but does not when I use it for subtracting to values. Here is what I have so far:

function calcDep1()
{
dblTotal = 0.0
for (i=8;i<=9;i++)

[Code]....

I have worked with it for several hours and also changed the equation to reflect dblTotal = dblTotal - dblValue but it still evaluates to a negative number. The two test values I used are 100 - 50 which should equal 50 but the answer always comes out to -150.

View 3 Replies


ADVERTISEMENT

Loop Through Struct Values?

Sep 27, 2010

I have a struct like this:

Code JavaScript:

function Sampe(name, value, unit)
{
this.name = name;

[code]...

I then have an array of instances of this struct. I'm trying to create a search feature and need to loop through each instance of the struct in my array. Then I need to loop through each value in the struct and check it for a substring. If a substring is found the entire struct instance is printed and the search will skip to the next struct instance. Right now my loops are not working properly. The loop below with 'item' is not correct as 'item' just prints out a number (should be a text value).

Code JavaScript:

function searchView(text)
{
document.getElementById("searchResult").innerHTML = "";

[code]....

View 3 Replies View Related

Subtracting Won't Work ?

Dec 25, 2011

<html>

I don't see that x loses 10 what's the problem.

View 1 Replies View Related

CPU 100% On A Loop While Retrieving Form Values

Jul 20, 2005

I have a form with a lot's of number of Text and Hidden Fields. I just do a simple loop to get each value for each attribute. I have about more than 2000.

if i do something simple like :

for (var i=0; i<2000; i++)
aValue = i+10;

it runs well. But if i do something like
for (var i=0; i<2000; i++)
aValue = document.myForm.elements[i].value;

it gives me 100% CPU for a long time before i submit the form.

View 3 Replies View Related

Return Sum Of All Input Values Within Loop

Jan 19, 2006

I have a bunch of input fields, each which will have a numerical value. There can be any number of input fields in the form, and that number will vary depending on what the user has selected prior in the application.

So basically I created a loop that goes though all of the INPUT fields within the form. How can I have it find the value of each field and add them all together, then return to me the total? It'll need to be made into a variable, but a simple alert with the total value will give me enough to work with.

View 2 Replies View Related

Adding And Subtracting Total

Nov 12, 2009

How to subtract totalgift if my condition of donateamount is lesser than the totalgift trigger.

When the field is selected and the DonateAmount is trigger, I need to subtract the entered amount on the field selected to the TotalGift and put the field selected to zero "0" and TotalGift to original amount which is less than the amount entered on the field selected. I have some code that I created but it doesn't work. My initial javascript to calculate all the total is below assuming that DonateAmount is already selected = 25:

Below is what I am trying to do but it doesn't work. If the first input field is selected and user enter amount greater than the TotalGift, alert will pop-up then and the amount entered by the user automatically added to the TotalGift. So what I wanted to do is to subtract the amount entered to the TotalGift so it will go back to the original amount before the addition occurs. I know it is possible but I just can't get the right code.

My html code below which I have 18 input fields but all of them only optional wherever the user wants to input number. I will only include some here. Code below works, please ignore any missing code. I just need the calculation code to work.

View 2 Replies View Related

For Loop To Write Out Two Matching Values In An Array?

Jan 26, 2011

Having a small problem with writing out the matches from an array using a For loop.

I have two arrays, lets say arrayA and arrayB. In arrayB are numbers which are a number of miles, ie 1,2,6,4,5,6,6. And in arrayA are the days of the week. Each day of the week is associated with a mileage, ie Mon = 1, Tues = 2 etc.

My script has found the largest mileage in arrayB. Next I have to find the days of the week that match this highest mileage and write these out, along the lines of "The highest mileage was 6 run on Wed, Sat, Sun."

I have managed to get a For loop to work with this BUT..... I can only get it to write out the first instance of the day the match is found. ie "The highest mileage was 6 run on Wed,"

[CODE]
maximumDistanceIndex = 0;
for (var distance = 1; distance < distanceArray.length; distance = distance + 1)
{

[Code]...

View 16 Replies View Related

Insert Values Into The Cells Of A Table Using A For Loop?

Sep 1, 2009

The Script below generates a sudoku (9 by 9) table and displays the table on screen.

what I am trying to do is to get a string of numbers entered into the text field labeled "enter values" on the page below the table, into each cell box of the sudoku table when the button labelled "load" is pressed. This would fill the sudoku table with characters, one character (from the text field) to each of cell boxes in the sudoku table.

It requires using a for loop, I tried using one in my function (g) but it doesn't work,..

<html>
<head>
<title>Sudoku</title>
<style type="text/css">

[Code]....

View 1 Replies View Related

JQuery :: Loop Through Field Values And Change Value?

Jun 16, 2011

Using JQuery how do you loop through fields taking a value from each one and multiplying with a specific value.

View 2 Replies View Related

Subtracting Discount On Order Form?

Jan 3, 2011

I have a custom order form that will add up and show the total but I'm having trouble getting it to subtract the discount. What changes do I need to make to my javascript?

The form is here: [url]

This is the javascript I'm using which is also viewable in the source code of the above form:

Code JavaScript:

View 8 Replies View Related

Assigning Array Values In A Compounding Loop - Keep Getting NaN Or Undefine

Sep 25, 2011

I am taking a js class and there is one minor bug that is driving me crazy with this assignment.

First, here is the code I wrote, then my question:

var games = ["Jacks","Chutes and Ladders","Extreme Uno","Bopit","Barbie Doll"];
var price = [4.00,15.99,25.00,27.99,32.00];
var inventory = [40,15,30,20,40];

[Code.....

I can't (just before this line) assign 0 to each array item - to get it defined because if the user goes back in and adds more, it will always reset the number back to 0, which is not what I wanted.

I tried adding an if..else statement instead, but cannot figure out how to get that to work?

View 9 Replies View Related

Subtracting From Health Variable Using OnClick Function?

Apr 2, 2010

I'm trying to create a short, html/javascript mario text game. Now, in the beginning, he fights a goomba.

He has a health and energy number as variables:

And then, there will be different buttons for different attacks. However, the only one created is "Punch", with this code:

What would I put in the onClick function to make it subtract 4 health from the goomba and 2 health from Mario.

View 2 Replies View Related

Logic Error In AcroJS - Subtracting Instead Of Toggling

Feb 4, 2011

Putting some javascript into a pdf file and can't get this to work out right.

Basic setup:

Field X = checkbox;
Field Y = numeric input field;

Here's what should happen (increment is toggled):

Y has a value. When X is checked, Y is increased by 5. When X is unchecked, Y goes back to its original, unmodified value.

Here's what really happens (increment is subtracted):

Y has a value. When X is checked, Y is reduced by 5. When X is unchecked, Y is reduced by 5 again. Anytime X is clicked on, Y is reduced by 5 yet again.

Here's the code:

View 2 Replies View Related

Loop Through An Array - Check The Values And Disable The Drop Down Accordingly - SelBox[i] Not Defined

Sep 15, 2009

I'm calling a function that I want to loop thru an array, check the values and disable the drop down accordingly.

[Code]...

I keep getting a selBox[i] not defined. Is it the xxx[x] = ?

View 3 Replies View Related

Oncheck Adding / Subtracting Not Adding Up?

Mar 4, 2010

I'm having a problem when I uncheck the box it should subtract the amount from the total which it does kind of. It subtracts a number other that one selected. When I put a alert into the function it pops up with the right amount.URL...click on "comps"uncheck the box under the zillow table.it should remove the amount of SqFt under the little table under the map.The only one that I've established is the zillow.[code]

View 1 Replies View Related

Recursive Function With For Loop, For Loop Is Breaking When Calling Itself

Jan 22, 2011

I have been looking at this code for two evenings now, and rewrote it 4 times already. It started out as jQuery code and now it's just concatenating strings together.

What I'm trying to do: Build a menu/outline using unordered lists from a multidimensional array.

What is happening: Inside the buildMenuHTML function, if I call buildMenuHTML, the for loop only happens once (i.e. only for 'i' having a value of '0'.) If I comment out the call to itself, it goes through the for loop all 3 times, but obviously the submenus are not created.

Here is the test object:

test = [
{
"name" : "Menu 1",
"url" : "menu1.html",
"submenu" : [

[Code].....

'Menu 2' and 'Menu 3' don't show up! I'm sure it's something small that I'm overlooking.

View 2 Replies View Related

Send A Loop Variable (i) To A Function Inside The Loop

Aug 4, 2011

I'm looking to send a loop variable (i) to a function inside the loop, but I can't seem to get it to use the value I want, it keeps making it a reference of i and therefore the function is always called using the last value of i rather than the one it was set with.

So if i have 5 Tabs then Tab 1, when clicked, should call DefaultTabClick(0) and so on rather than always using 4 for any of the tabs.

View 2 Replies View Related

JQuery :: Loop Forever And Reload Xml Each Loop?

Jul 29, 2011

I have the code below, how could it be modified to loop over and over and reload the xml file each time. Flow would be: load xml, run thruogh code to display each xml node one at a time, when reach last node, start all over, reloading xml file,

[Code]...

View 2 Replies View Related

While Loop Or For Loop For This Script Involving Arrays?

Mar 6, 2011

As you can see from the code and the output, it will attempt to write to the browser how many moves, but only '0'.

function rollDie()
{
return Math.floor(Math.random() * 6) + 1;
}
/*
*searches for a number in a number array.
*
*function takes two arguments[CODE]...

View 5 Replies View Related

Changing For Loop To While Loop?

Nov 12, 2010

I am doing some studying and we was to create a small loop using either the for loop, while loop or do while loop. I chose to do the for loop because it was easier to understand, but I want to know how to do the same using the while loop. Here is the for loop I have, but I cant figure out how to change to while loop.

for (var i = 0; i < 5; ++i)
{
for (var j = i; j < 5; ++j)
{

[Code]....

How do you make the same using a while loop?

View 2 Replies View Related

For Loop Wont Loop?

Jul 5, 2010

it wont loop,as long as you enter something in the name field it will submit. also how do i stop from submitting if all fields are not filled out?

function checkForm(form)
{
var len = form.elements.length;[code]....

View 3 Replies View Related

JQuery :: Checking Multiple Input Values Against Various Other Hidden Minimum Values

Jul 19, 2011

I have a list of products where they have minimum quantities in a hidden input. Some products have multiple colours, though the same minimum quantity and I'm trying to implement a jQuery check that entries made are at least equal to the minimum.

Blank or '0' entries are fine but if it's below the minimum quantity it should set to the minimum.

HTML:

Is there something obviously wrong with this? It isn't performing the minimum check and I'm really not sure why.

View 1 Replies View Related

Ajax ::Submit Inputs Values Using Normal Button / How To Keep And Clear Values

Apr 15, 2010

In part of my form, I have 3 inputs (one textarea and two text inputs),I am validating their value format using AJAX (each input triggers error message on its label in case format is wrong). Also I have one button, "NOT submit button" (type = button).Now, when clicking on the button it must enter the value of those three inputs in my database in case they are true then all inputs values must be cleared. In case AJAX validation is wrong and in case the user clicked on that button, the value of fields must kept as it is.

Actually I can not use submit button because I have it for the whole form and what I am taking about is a part of the form and it's not possible to make nested forms as I know it violates html rules. It's easy to make it if I am taking about submitting button as I can view session values on fields after submission in case ajax returns error.I can clear inputs from Javascript, but it will be cleared on both cases if AJAX validation true or wrong. Each input field has AJAX Error message that will be triggered when the input format is wrong.

View 3 Replies View Related

Comma Separated Values - Form That Gets Values That A User Has Selected From A List Menu Field

Jul 6, 2009

I have a form that gets values that a user has selected from a list menu field, that end up like this added to the URL:[url]

Instead of the Field being mentioned more than once, how can I have it where it could mention the field once with the values coma separated eg:[url]

Would I use JS to change the URL? or VBscript?

View 30 Replies View Related

Stylized Text With Absolute Values Vs. Relative Values And Scalability On A Mac

Sep 19, 2005

I built my company's website and the content portion of the site uses
text with styles with relative values and the navigational part of the
site uses text with styles with absolute values. The purpose of this
was so that the end user could increase the size of the text on the
webpage and only the content portion of the page would scale or resize
but the navigation would not. This works as expected on a pc but the
entire page scales on a MAC. Does MAC not support text with styles the
same as pc so that the only scalable text is that with relative values
(ie: small, x-small, medium, large, etc)? Absolute values conist of
point sized text. Code:

View 2 Replies View Related

Process Text Box Values/ Call Textbox Values To Program?

Oct 1, 2010

How to process textbox values/ call textbox values in JS through a Java program.My text box values are dates. I have to process these dates. Like in online banking we select day to know our transactions. After submitting we get results. remember my files are in my directory only. No need of database. My files are look like 20100929, 20100930, 20101001

For epoch_classes.js, epoch_styles.css u can download coding from this link : http:[url].....

Code:
<html>
<table width="900" border="0" cellpadding="10" cellspacing="10" style="padding:0">
<tr><td id="leftcolumn" width="170" align="left" valign="top">[code]....

In my coding, ys, ms, ds represents year starting, month starting, starting day...ye, me, de represents end...start,end gives file names in the format of yyyymmdd.now i want to process files from 20100101 to 20100930

means from date is 2010/01/01 and to date is 2010/09/30

if i press submit button the files from 20100101 to 20100930 are processes

here ys=2010 ms=01 ds =01 and ye=2010 me=09 de= 30

For this how do i call these textbox values (from date text box and todate) to another program (java)

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved