# Calculations With Arrays

Sep 12, 2006

I want to make algorithms that take selections from arrays and put them together in new ways. here is a simple array I set up for notes of a piano keyboard: Code:

## Using Images And Arrays To Make Calculations...

Nov 27, 2005

I have 6 images (representing each side of a dice). I need to display two of these images randomly when the user clicks "Roll the Dice!". I have set up an array with all my images contained, and I have no problem getting two random images to display when the user clicks the button. This is the easy bit. Here's my code:

## Lost In Calculations

Sep 11, 2003

I have a wapper here, and I'm going crossed eyed trying to figure this one out. I have a form with Radio Buttons for my customers to purchase a customizable club program. I have 5 sections each of which cost a certain amount. Then I have another section that lets the user pick what duration they would like, 3, 6, 9 and 12 months. Each option has a certain % taken off the retail price. 5%, 10%, 15%, 20% depending on the duration option. All calculations are done on the fly as customers click the radio buttons. I do have it set up and working, only I have the duration listed as many times as my sections. I would like to have only one duration section. I'm not sure if this is done in java or HTML....

## Form Calculations

Apr 12, 2005

I am making an order form that will serve as a very basic solution for a small company

I need to calculate the total either with on_change or with a button

currently I am using this code

onClick="document.orderm.gtotal.value =
parseInt(document.orderm.line1price.value) +
parseInt(document.orderm.line2price.value) +
parseInt(document.orderm.line3price.value)">

but if line3price is left empty I get NAN as total

how can I bipass line3price if this field is empty?

## Calculations / Multi Forms Etc

Nov 8, 2005

I got the following code running on a seperate page but how could I do it without forms? the page I wish to put it on page is one big form and therefore nested forms are a no no.

<script>
function calc() {
var inp = document.ccForm.inpt.value
var inp2 = document.ccForm.inpt2.value
var outp = 0
outp = inp * inp2
document.ccForm.outpt.value = outp
}
</SCRIPT>

<FORM ACTION="#" NAME="ccForm">
<INPUT TYPE=TEXT NAME="inpt" SIZE=10 VALUE="2.9" ONCHANGE="calc()">
<INPUT TYPE=TEXT NAME="inpt2" SIZE=10 VALUE="2.9" ONCHANGE="calc()">
<INPUT TYPE=TEXT NAME="outpt" SIZE=10 DISABLED>
</FORM>

## Add Calculations To Mysql Values ?

Jan 11, 2011

I have a script with the following:

I need to do the following:

When the amount boc changes value, it must change the \$credit amount and effect the \$total_crt amount (ex. 10 + 10 in credit value - \$total_crt value) So whenever the client chooses a new value from the select box, it must change it emidiately with javascript, but only send to the database once an update button is pressed.

Here is a quick example of my code:

## Getting Values Of NaN In Floor Are Ratio (FAR) Calculations

Aug 5, 2009

I have a form which is used to calculate residential Floor Area Ratio (FAR). The form is structured into seven parts as follows:

Part A: Maximum FAR and Floor Area:

Part B: Gross Floor Area of the main floors of the main house:

Part C: Gross Floor Area of the basement or cellar:

Part D: Gross Floor Area of the attic:

Part E. Gross Floor Area of all accessory structures except detached garages: (including cabanas, guest houses, caretaker's cottages, pool houses, sheds, barns, or other structures except a detached garage)

Part F. Gross Floor Area of the garage: (not including basement garages)

Part G: Total Floor Area:

The Javascript involved in the calculations is as follows:

[CODE]

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
function checkAllInputFields(){
IsValidEntry(entireForm.A1.value)
IsValidEntry(entireForm.A5.value)

[Code]....

I have attached the html file as a .txt file for reference, and I have attached a .txt document including all the values I used for testing.

## Calculations Based On User Input?

Jul 14, 2010

Dear expert (Ok, i am new to this and should maybe not address this as a letter )I hope someone can help me ... this is what i want to achieve (I am using frontpage)I want to create a table (this i can do!) that require a user input (number of guests).It then has SEVERAL options:- Select an option from a drop down list, and a price is then loaded from somewhere to create a total for that option and display it in the table (And keep that total for adding later)- Check a box, and if checked it creates a further calculation, displaying and storing the number for further calculation.a number of the above options, and a grand total on the bottom.I found more or less a page on a site that does what i am looking for, but after looking at the code, i have even LESS of an idea how it works Can someone PLEASE help me, or point me in the right direction?(I am not looking for someone to just write the code for me, as this will not teach me anything, and i want to learn)

## Display Array Values / Calculations Into A Div?

Jan 2, 2011

Decided to start learning JavaScript, started 2 days ago. Anyway, I'm trying to create a simple script spits out a styled result based on a user input. code...

The problem is that nothing is happening when I press the calculation button.

What I would like to happen is to display a div element for each value in the array which displays the entered value from VenCost2, the current Margin %, and the result of VenCost2 * margin%. I want this to display on the same page and underneath the calculation button, preferably not having to reload the page.

## Refresh Calculations Without Submitting Form?

Feb 25, 2011

I want to refresh the calculations on a form without submitting the form. I have tried two different JavaScript button codes, and I'm wondering if there is a reason for using one over the other, and if there is something else better for cross-browser use.

1) [ICODE] _doClick('\$Refresh', this, '_self')
2) [ICODE] _doClick('\$Refresh', this, null, null)

## Calculations With Inside A Html Form?

Mar 24, 2011

I'm looking for some help with something I have been developing over the last day or so. Basically, I have a form with some input boxes in it, and I am trying to use some javascript to do a calculation with these input boxes. The problem is that when I go to click on the "calculate" button nothing happens. The fields where the value should go to I have made visible instead of hidden to make sure that something is going there but nothing is appearing.

I've checked various parts of my syntax with online checkers and other javascript examples and I'm stuck as to what has gone wrong. If anyone can shed some light on the problem and possible solutions that would be awesome.

[Code]...

Edit: I have edited the code to remove/change the things that "Philip M" kindly pointed out were not needed and a bit of re-designing the page. I still can't get the javascript to put the answer value in the correct place on the click of the button. I'm under the impression it has something to do with the button rather than the javascript code but I might be wrong.

## Ignore Daylight Savings In Date Calculations?

Sep 19, 2005

I have some date calculations that add a time span to a date. The problem is, when I add a time span that is a whole number of days to a date, the result can be +/- 1 hour due to daylight savings. Is there anyway to disable this?

## Have A Submit Button To Do Some Calculations Before The Whole Form Submits?

Dec 1, 2009

just wondering can i have a submit button to do some calculations before the whole form submits like this?

Code:

<form>
<options selected></options> <calcTotalSubmitButton>
<SubmitWholeForm>
</form>

how do i call the first submit button to submit what the user has entered, before submitting whole form?

## Radio Buttons To Perform Simple Calculations?

Apr 3, 2009

I have a matrix of radio buttons:

[Code].....

The colum totals would change to: 2, 0, 1 and the total would be 3

I basically need the total of each column and the total overall. The value should be taken from the actual "VALUE".

## Performing Calculations In A Webpage With An External Javascript File

Jan 13, 2006

I work for a small college and we were recently given permission to use a particular GPA calculator on their website. They sent us a javascript file, that I now have. I am trying to incorporate this into our website, but I don't really know much about javascript and I am having trouble making it work.

You can view the GPA calculator here to help clarify what I mean... If someone could just help point me in the right direction or if anyone know a site with tips that would be helpful to me..

## Checkbox Calculations - Total To Be In Plain Text And Not In A Text Box Maybe Just Drop The Total Value In A DIV

May 5, 2009

My requirement is to develop a simple form with checkboxes which when selected calculate a price based on the value assigned to the checkbox. The form and calculations is working great but i need a few final touches which i can't work out.

1. I want the total to be in plain text and not in a text box maybe just drop the total value in a DIV.

2. I want the form to start with a default value for example 200, i have tried adding a hidden checkbox with a value of 200 and setting it to checked as default but it doesnt display 200 in the total when i first load the page it only calculates it when i select the first box and i need it to be displayed as the total even if no options are selected.

[Code]...

## Arrays And IE

Jul 23, 2005

I've noticed that IE apparently has a horrible implementation of the
array object, since traversing one with as few as 1000 items it tends
to pop up a dialog informing the user that the script is taking too
long. I tried splitting the array into a 10x100 two-dimensional array
as well as changing the array to a linked list, but neither improved
the code's efficiency sufficiently. Can anyone suggest methods for
optimizing array efficiency, or some other workaround for yet another
one of Bill Gates' blunders?

## Xml Vs Arrays

Jul 23, 2005

I have a web document created by a script and instead of going back to
the db I choose to either create an array to iterate through or xml to
parse through.

So, my question is: What are the trade offs between using an array to
load data from or an xml structure?

My array would look like:

myarray = [[],[],[],[]]

My xml like:

<xml>
<data>
<a></a><b></b>
</data>
</xml>

I would use js to iterate or getElementByTagName to find data. I am thinking the page would load faster using xml, and then the user may not even use that functionality. In all cases I have to load the array to memory.

## Arrays Different In IE And Others?

May 23, 2007

I am with XHTML and CSS as much do I have to learn in JavaScript programming. I’m just beginning to understand and modify the DOM and I ran into something that I couldn’t find a solution for after some extensive search. I have this function:

if(document.getElementById && document.createElement) {
var children = document.getElementById('pagelist').childNodes;
for(var i = 0; i < children.length; i++) {
children[0].className = 'bulgaria'
children[1].className = 'england'
children[2].className = 'italy'
children[3].className = 'sweden'
}
}
window.
}

The XHTML is an unordered list with 4 list items and sub lists in those list items (plus links in each li) and I want to add a country flag (set as background image in the CSS) to the direct children of the ul (the first level list items).

Now I discovered that Firefox is only reacting to odd array numbers, i.e. children[1], 3, 5, and 7 (the even numbers have "no properties") while IE is applying the classes correctly(?) as intended above (0,1,2,3).

At which point did I go wrong? Sorry if this is a real stupid question but I’m pretty new in this field and my researches didn’t bring any acceptable results.

## Arrays Of Arrays...

Oct 5, 2005

Is what I'm doing the right approach to creating an array of arrays? I have an external datafile with several employees' records. They are stored in an array with each element of the array being the complete employee record, ie: name, date of hire, etc., etc. These attributes are delimited by a :. I'm trying to separate these attributes while keeping the original array intact. That way I can access these attributes and validate whether or not an instance of the employee object will occur. There are too many records to create this from the start, so I'm trying to implement a for loop to do it for me. This is what I tried: datafile is the name of the original array of employees. emp is the array I'm trying to create .

for(var i=0;i<datafile.length;i++){
var emp = datafile[i].split(":");
//document.writeln(emp.length+"<br>");
/document.writeln(datafile[i]+"<br>");
}
//document.writeln(datafile[0]+"<br>");

## Arrays And Selects

Jul 23, 2005

How do I set this to "disabled":

<select name="awards[]" multiple size="6">
<option value="1">Award 1</option>
<option value="2">Award 2</option>
<option value="3">Award 3</option>
<option value="4">Award 4</option>
</select>

I don't know how many options there will be as they are fed from a DB.

## Suggestions About Using Two Arrays

Nov 23, 2005

Anybody got any suggestions about using two arrays. First i need to
ask the user their name and if their require a seat between 1and 5 or
between 6 and 10. I need to assign this information in two arrays.
Any suggestions. I have been working on this so far.
<script type="text/javascript">

var theArray = new Array(10);

//var sizeOfArray = parseInt(prompt("How many items will the array
have?", ""));

for(i=0; i<10; i++)
{

}

for(i=0; i<theArray.length; i++)
{

document.writeln( "theArray[" + i + " ] = " + theArray[i] + "<br />");
}
</script>

## Strings As Arrays

Mar 6, 2007

Safari and FF seem to allow this:

var wiggy = "ABCD";

ch = wiggy[2]; // ch will contain the character 'C'

however my JS book seems to insist that I do this:

ch = wiggy.charAt(2);

and indeed doesn't appear to mention the first method at all.

Since for my particular purpose I want to treat the string as an array
of single characters, I prefer the first method rather than the second.
Is there any reason not to pursue this approach?

## Assigning Between Arrays By Value

Jul 20, 2005

Any neat way to copy a snapshot of one array to another?

A normal assignment results in the second array pointing to the first,
with changes to either array affecting both.

As a trivial example:

var a=new Array();
a[0]="zero";
var b=a;
b[1]="one";

.... this results in a and b being identical two-element arrays.

Is there any easy way to set array (b) to be a copy of (a) BY VALUE -
ie using the contents of (a) as they were at the moment of assignment,
but leaving the two arrays separate so that subsequent changes to one
array does not affect the other?

## Arrays And Functions

Jul 20, 2005

looking for a way to pass an array to a function.
====================================
<script>
function myfunction(arrayname)
{
document.write("blablabla"+ arrayname[1] +"blablabla");
}
</script>

<html stuff>

<script>
arrayname = new Array("what", "is", "wrong");
myfunction(arrayname);
</script>
====================================

## How To Add A Method To A Set Of Arrays

May 18, 2011

I'm a newbie of JS and don't know if I have got the right terms in my question. I want to lowercase all the arrays:

<script>
var txt = [
["Cats","Dogs","Rabbits"],
["Fish","Bones","Carrots"]
]
document.write(txt[0][1] + " love eating " + txt[1][1]);

[Code]...