Unable To Execute Function Designed To Calculate The Average Of Numbers Inputted?
Oct 4, 2010
I've been messing with this code for about a couple of hours, and I did everything down to the wire..yet still I am unable to get it to work. When I input the numbers, and click off to the side nothing appears down at the final textarea of the form which is suppose to show the average.I've tried just about everything, sadly all I have to go by is other example codes, and the very intricate instructions which states I must pass the values to the calcAvg() to the second function of performCalc(), which I did, and then I assigned the var calcResult another value. From there I did the return..and after that I'm rather loss as to what to do next to get this code to work, any tips?
<!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">
How do i use a function to find the average of the values in an array of numbers passed as argument to a function.(using java script) thank you for your help...
I made a form with text inputs but notice you can use special symbols. I want to only allo charaters like letters and numbers that is it.Is there any jquery function that cna do such a thing... if not how do you implement something that will filter it.
i am trying to create a interface to average down variable amount of input and show them on screen as they type....this is what i came up with.....and the input box fields....these are dynamically created...
My knowledge of programming is very limited. I would like to calculate the average of session variables in Interpreted Java. However, some of session variables may not always be available. The first thing I do is remove the non numerical portion of the session variables:
String [] variables = {"A",'B','C','D','E'}; i = 0; Iterate through each variable in the array above while (i < variables.length){ Get the variables to be fixed value = session.getVariable(variables[i]); Log the UNFIXED values session.log("UNFIXED: " + variables[i] + " = " + value); if(value != null){ Remove non-numerical elements value = value.replaceAll("\\D", ""); Set variables with new values dataRecord.put(variables[i], value); session.setVariable(variables[i], value); Log the FIXED values session.log("FIXED " + variables[i] + " = " + session.getVariable(variables[i])); } i++; }
Then I make sure the session variables can be treated as numbers: A = Integer.parseInt(session.getVariable("A")).intValue(); B = Integer.parseInt(session.getVariable("B")).intValue(); C = Integer.parseInt(session.getVariable("C")).intValue(); D = Integer.parseInt(session.getVariable("D")).intValue(); E = Integer.parseInt(session.getVariable("E")).intValue(); Are they still alive? session.log("A**" + A + "**"); session.log("B**" + B + "**"); session.log("C**" + C + "**"); session.log("D**" + D + "**"); session.log("E**" + E + "**");
I would like to calculate the average of A and B and save it as session variable AB, calculate the average of C and D and save it as session variable CD, and then the average of AB, CD, and E. Here's the weird part; AB, CD, and or E will not always be available. For example, AB will not be available so I need to calculate the average of CD and E or E will not be available so I need to calculate the average of AB and CD. As I said, my knowledge of programming is very limited so if you could provide code snippet with explanation of each step and where to plug in my session variables.
I need to find the average number in javascript. It is the only bit of javascript that I have to do in the course but it carries a high mark of which I cannot afford to lose. Any way the question is : "Write code to calculate the average height and write it out in the browser window"
<HEAD><TITLE> average</TITLE> <SCRIPT LANGUAGE = "JavaScript"> //Experimental results of Table 1 stored in arrays. var Height = [15,16,17,18,19]; var Number = [2,1,6,4,2];
//Part (ii). //Write code to declare and initialise new array to represent the third row of the table. var avg = new Array(5) var avg = ["60","80","187","180","114"] ; avg[0] = "60"; avg[1] = "80"; avg[2] = "187"; avg[3] = "180"; avg[4] = "114"; //Part (iv). //Write code to calculate the average height and write it out in the browser window. avg = 0; for (var count = 1; count <= 5; count = count + 1) Array.average = function(){ var avg = 0; for(var a = 0; a < this.length; a++){ avg += this[a]; } return avg / this.length; };
document.write('average height is ' +avg + '<br>'); </SCRIPT></HEAD><BODY> </BODY></HTML>
I am not able to calculate the offsetwidth of the element which contains extra space in between the characters.for ex. if the element contains "A A" as a innerHTML value - if we calculate offsetwidth as 29 and also if the element contains "A A" value again I am getting the same offsetwidth as 29.While calculating the offsetwidth it is not calculating the empty space.May I know how to calculate the offsetwidth with the empty space because I need to insert the ellipsis (...) if it exceeds original width?
Code snipet function fitStringToWidth(title,width,className) { var span = document.createElement("span"); span.className="titleBar-Title-1";
This is my second attempt at code to allow the user to view a table by navigating through a page using customised buttons. Although all buttons work on the 'MouseDown', event, the 'MouseUp' is not working. Any ideas? Code:
This jquery code pulls in an XML file, then passes the contents down to the nested POST call to add all of the records from the XML into a database table (which is handled by the saveSenatorRecord.asp file). This all works fine.. except that when the POST is called for "EACH" of the member nodes I expected the success: function to be called once after each of the records are added to the table. But what appears to be happening is that when function is called in the EACH property... it adds all of the records to the database table at one time, THEN it calls the success function once for each individual record.. but AFTER they have all been added.
Do you know a function for banning certain words being inputted by the user eg I want to stop a user uploading offensive words and code tags like <script>, <div> etc.. and messing with the site display
How do I search through an array looking for an inputted entry? Ihave this so far. Also need it to display where the object was found. var states = new Array(); var i; i=0;
The function is called from a child popup window which closes the child when called. The function works well however when the child window is closed the cursor on the parent window continues as if it is trying and load something (although nothing is being loaded). Do I need some sort of end function to close the function off after it is executed?
I've been looking all over for an explanation of this function declaration but cant find it. what it means to have a function with no name, just declared as this. When does it execute? How does it get called?
I need to execute a function after a link to a section within the same document has been clicked and the navigation has occurred. When using the onclick event handler the JS function is executed before the navigation occurs. I can't tie it to a window.onload event since the link only navigates within the already loaded document.
I'm not having any luck searching due to not knowing what keywords to use. I looked at an explanation of bubbling vs capturing, but that doesn't appear to be what I need.
Just posted this thread a few mins ago and for some reason it got deleted? Maybe it was because of the URL shortening I used. Anyway here is an example of what I mean
I have this code which removes a class from an item on mouse out.
Code:
function mouseOut8( ) { $('.bar8') .removeClass("barover"); }
I would like to change this so that the class is removed from the item I have just moused out of instead of specifying the exact item. This is so I can use this function for multiple items. I tried replacing the '.bar8' with 'this' but it didn't work.
I have long html/CSS (no CMS or php, etc.) web pages. Some people run away when they see too much content on a page. So I hide the large lower section of the pages and have the user click anchor text to execute simple JS code to change the display from 'none' to 'block' or back to re-hide.
Code:
(BTW my research indicates that search engines do not know the difference between display='none' and normal content, or I would not be hiding content in the first place.)
Within this hidden content, I have anchor text to provide name handles
Code:
So users can click a link and go directly to that section. Within that link I include
Code:
So that works fine within a particular page. But when I want to link to an anchor on another page which is within this hidden content, the browser cannot display the anchor text because it is still hidden.
Is there a way to execute the JS code to change the DOM, changing the display to 'block' on the content of the new page?
I do not see how, because the new page isn't loaded yet, there is no DOM within the browser yet, so how can it be manipulated?
Of course if I was using php I could generate the code with the property set as desired. But for straight up html/CSS/JS pages is this possible?
I get the feeling I am missing something simple here, either a simple solution or the simple fact that this is just an inherent limitation of html.
I have been trying to work my way around this issue for some time now. I am trying to stop a marquee from scrolling as soon as the page start to load not after. I have been using this to pause the marquee with JavaScript but the command does not execute but after the page loads; after all the html loads.
With this code the marquee does stop but after the page loads completely so as the page loads the marquee start to scroll and then stops as soon as the page finishes loading but with the first image of the marquee have way out. I need to be able to load the marquee 100% stopped as the page loads so then I can use the buttons I placed to control the marquee.
My question is:
Is there ANY way to completely stop the marquee from scrolling as soon as the page loads??
how to scroll the marquee by click; meaning by every click of the mouse the marquee moves either left or right, would be even better. p.s: Noted that this code does NOT work in FF for some reason. The stop does not work and the buttons don't respond. why in FF they don't work but in GC and IE they do?
I have a javascript code which makes a word toggle links under it. For example: Before clicking on it it looks like this: Stories: then once its clicked on it looks like: Stories: story 1 story 2 story 3
How can I make it so when you click stories it creates that list and also goes to story 1. Here is the code I have: Code: <h2 style="margin-left : 25px;"><img src="/images/sort_ASC.gif" id="img_DegreeList5" alt="" /> <a href="javascript:toggleDegreeList(5);" style="color:#336699;">Teaching Tales</a></a></h2> <div id="DegreeList5" style="display:none;"> <ul><ul> <li><a href="teaching_tales1.php">Story 1</a></li> <li><a href="teaching_tales2.php">Story 2</a></li> </ul></ul> </div>
And here is the toggledegree script Code: <script type="text/javascript"> var currentDegreeList = null; function toggleDegreeList(which) { if(currentDegreeList) { document.getElementById('DegreeList'+currentDegreeList).style.display = 'none'; document.getElementById('img_DegreeList'+currentDegreeList).src = '/images/sort_ASC.gif'; } if(currentDegreeList != which) { document.getElementById('DegreeList'+which).style.display = 'block'; document.getElementById('img_DegreeList'+which).src = '/images/sort_DESC.gif'; currentDegreeList = which; } else { currentDegreeList = null; } } var submitted = false; function submitForm() { var val = (submitted) ? false : true; submitted = true; return val; } </script>
If you actually want to see the live page its here [URL].