Javascript Calculation Onload
May 14, 2007
I currently have a web page that is building a web form from data contained in a SQL table. I need to do some calculations on the numbers that are populated into the form. I have used the following javascript code to successfully complete my calculations but I can only use this code at the bottom of my page because executing it at the top of my page the form fields are still empty. How would I use or modify the code I have to display the calc at the top of the web form. Example as follows:
<form method="POST" target="_self" name="dialer" enctype="text/plain">
Loan Amount: <input type="text" value="400000" name="loan" />
Interest Rate: <input type="text" value="1.00" name="apr" />
Amortization Term: <input type="text" value="480" name="term" />
</form>
<script language="JavaScript">
var princ = document.dialer.loan.value;
var term = document.dialer.term.value;
var intr = document.dialer.apr.value / 1200;
var output = princ * intr / (1 - (Math.pow(1/(1 + intr), term)));
var calc = (Math.round(output * 100)/100);
</script>
View 1 Replies
ADVERTISEMENT
Nov 4, 2006
Okay you know how you can do something like...
window.onload=function(){myFunction();}
in order to contain all you javascript in the head of your document??
Well why can't I seem to do...
document.getelementbyid('MyElement').onclick=function(){myFunction();}
??
View 13 Replies
View Related
Jul 23, 2005
I'm having a hard time figuring out why the onload event is not being
called for the frameset window in the following simple example. It is
being called for each of the component frames. Code:
View 5 Replies
View Related
Dec 3, 2005
I wander what gets loaded the fastest (1-2 or 3) in what succession:
<head>
<script type="text/javascript">
function andAction() {
// doing stuff
}
</script>
</head>
<body onload="andAction();">
<script type="text/javascript">andAction()</script></body>
just in the head and nothing more
This I am sure off:
<head>
<script type="text/javascript">
window.onload = function andAction() {
// doing stuff
}
</script>
</head>
<script type="text/javascript">andAction()</script></body>
just in the head and nothing more (should be 1)
Third and last which is faster:
body onload or window.onload
View 3 Replies
View Related
Jul 20, 2005
I have the following script in an html page:
function goToPosition()
{
varGoTo = document.write(document.cookie("Position"));
document.scrollTo(0, varGoTo);
}
</head>
<body
When I put the in, I get the error message
"object doesn't support this action". I've also tried putting in after
the </body> tag as another script...no go.
I'm setting the cookie with these lines in another function:
varScroll = document.body.scrollTop;document.cookie("Position") =
varScroll;
Any clues/suggestions greatly appreciated. I recently posted a similar
question, but rearranged how I was doing it, still no luck, so I'm
trying again.
View 4 Replies
View Related
Nov 23, 2005
I have been trying to load a javascript function from the body onload
html tag, but I only want the function to load the first time the page
is loaded: I have investigated but haven't found anything that works..
I thought about cookies, but what if the user's disable them?
My code:
//I want to call the Toggle function below only on the 1st time the
page is loaded:
<script language="javascript">
function Toggle(item) {
obj=document.getElementById(item);
visible=(obj.style.display!="none")
key=document.getElementById("x" + item);
if (visible) {
obj.style.display="none";
} else {
obj.style.display="block";
}
}
function Expand() {
divs=document.getElementsByTagName("DIV");
for (i=0;i<divs.length;i++) {
divs[i].style.display="block";
key=document.getElementById("x" + divs[i].id);
key.innerHTML="<img src='textfolder.gif' width=ï ' height=ཕ'
hspace=Ɔ' vspace=Ɔ' border=Ɔ'>";
}
}
function Collapse() {
divs=document.getElementsByTagName("DIV");
for (i=0;i<divs.length;i++) {
divs[i].style.display="none";
key=document.getElementById("x" + divs[i].id);
key.innerHTML="<img src='Button1_01_over.gif' width=ðC'
height=ཡ' hspace=Ɔ' vspace=Ɔ' border=Ɔ'>";
}
}
</script>
// C# code I inserted above the body tag on my aspx page:
function handler()
{
if(<%=!Page.IsPostBack%> )
{
Toggle('support');
}
}
//The body tag with handler being called:
<body onload="handler()">
FYI: The Toggle('suport); function is not being executed. If i put the
function in the <body onload tag.. it does run..
View 1 Replies
View Related
Jul 23, 2005
I'm seeing a difference in behaviour between
window.onload = f();
and
<body onload="f();">
Specifically, window.onload appears to fire before all the elements of
the page have been rendered. As the difference is consistent across
IE/Moz/Opera, I'm assuming it's deliberate - can anyone point me
towards where this behaviour of window.onload is defined in the
documentation? TIA. Code:
View 2 Replies
View Related
Mar 7, 2006
I have the two text boxes on a form, both of which a user enters a
number. I simple need to ADD THESE UP!
I know, its daft, but no matter what I do, it just adds them together.
Example: 1+1 is clearly 2, but it outputs 11!
An example of my code:
var loan = document.loandata.loan.value;
var other = document.loandata.other.value;
total = (loan+other);
View 5 Replies
View Related
Jan 7, 2007
I am trying to make a script that prints a date in the format Sunday
14th January 2007. Where the date that is displayed is the next sunday
3 weeks from now. For example today is 7th January. The script would
print Sunday 28th January 2007. It would read that all of this week
until next sunday when it would change to Sunday 4th February.
View 12 Replies
View Related
Feb 5, 2007
It's probably something with rounding off, or floating point problems.
I have a timer which is used when solving the Rubik's cube. It has to
measure an exact time, but the clock display I made shows a different
value than the actual time (also displayed after session: ...). I am
using the same variable for both displays. sometimes it's off by .02.
View 1 Replies
View Related
Jan 4, 2010
I'm building a form that is calulated based on the options selected with a javascript form. This is my first attempt at something like this so I'm a bit lost at the final update.
First to be sure I'm on spot here is the javascript I'm using to update the form - <script>
function BDWcalc ()
{
[code]....
View 6 Replies
View Related
Sep 22, 2011
I have a javascript that should convert any date into a number between 1 and 260. Based on the outcome of that calculation, a viewer is directed to a specific web page.How can I verify the calculation? How can I see what number javascript is arriving at so I can backtrack to the error? It is not serving up the correct page.
I have compared the results to a calculator on another website [URL] that uses a different script to calculate the same result -- that's why I am saying the end results are not correct. On the other website, scroll down to where you enter a date. It returns a name just above the date (example: July 25, 1970 returns Electric Star). The script I included above returns Yellow Sun. July 25, 1970 should = 68.
function calculate() {
if(!isValidDate())
return;
[code]....
View 19 Replies
View Related
Aug 19, 2009
Please take a look at the picture below:When you enter the value of Volume and Unit Cost... it should automatically add up into Net Cost and VAT (including float number).
View 1 Replies
View Related
Nov 17, 2010
f
Code:
unction up(){
var inpt= document.getElementById("item_one").value
document.getElementById("aCom_total").value=Math.floor(inpt)
}
function up2(){
var inpt= document.getElementById("aCom_total").value
[Code]....
I input the valve 100 in textone my total =100 I input the value into 20 text two my total is not 120, but 10020
View 2 Replies
View Related
Jul 20, 2005
I have a form which must calc the difference between 2 date fields and
return the result in a third field. I have the following code but it does
not seem to work. Can anyone tell this total newbie where he is going wrong
or suggest a more elegant way of doing this.
<head><script>
function doit(oForm, usrInp)
{
var one_day = 1000 * 60 * 60 * 24 ;
var userDate = new Date(usrInp)
var dueDate = new Date(usrInp)
diff = dueDate - userDate
oForm.diff.value = (diff/one_day) + ' days'
}
//-->
</script>
</head>
<body>
<form name="a">
<input type="text" name="userDate" >
<input type="text" name="dueDate" onblur='doit(this.form, this.value)'>
<input type="text" name="diff" onfocus=this.blur();>
</form>
View 6 Replies
View Related
Jul 20, 2005
I've got a small problem here. I'm trying to write some code that would
generate a drop-down menue for me, where I'd just need to enter the
menu- and submenu items into an array. The items are to be displayed as
text. Now, I want to have the layers with the submenues to appear more
or less under the appropriate main menu items. For this I need to be
able to calculate how many pixels a given text uses up on the screen of
the user. That's all fine with IE and an unproportional font like
courier. The problem is, there is this nice setting that allows you to
change the diplay size of the text - which is pretty much disfunctional
in IE, but in mozilla, it works. Which means that I can't just say that
one letter in courier, size 2, is 4 pixels wide and be happy with my
calculation, because then somebody can just pop up with another text
diplay size and *boom* - my calculation is wrong again.
Now, is there a realistic way to find out how many pixels _exactly_ a
piece of text takes up on the user's screen? Or can I make the given
piece of text a DIV and then have some kind of document.divname.left
that gives me the actual location of this text?
View 2 Replies
View Related
May 6, 2010
I'm looking for a jquery tutorial which helps on calculating the distance between two points?
I've found a few javascript ones, but its breaking the rest of my jquery code!
does anyone know of anything? im using it to calculate a price for a specific distance traveled.
View 2 Replies
View Related
Aug 3, 2010
I'm creating this form that when you tick a checkbox, it adds the value of that checkbox to the running total. Then it displays the Calculation and Running total.
Code:
<html>
<head>
<script type="text/javascript">[code]....
View 6 Replies
View Related
May 11, 2009
I'm working on a page that needs to do some calculations based on values that the user inputs via sliders. I can get the values selected to display in a text box below the slider, but I also need to store the value as a variable for use in calculations.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
[Code].....
View 2 Replies
View Related
Mar 3, 2009
I try to calculate all the number based on selected radio button and display it in the textfield on the same page can someone can tell me the errors and suggest how to make my calculation is right.
[Code]...
View 9 Replies
View Related
Mar 14, 2009
Trying to figure out a problem with the "Optional" values in a list box so I am going to keep it as simple as I can..
I am trying to calculate the optional value of a list box in stead of programming it the long way around.
I created a list box with several peoples names, like John, Sue, and Mary.
I have assigned each name a numeric "optional" values
I know the code in the list box should be:
Normally, I would code this along the lines of:
But I want to figure out how to select the Optional Value from the list, and multiply it by time instead of doing the SELECTEDNAMELISTBOX=="John" route..
View 4 Replies
View Related
Feb 14, 2009
I am facing following problem while trying to embed JQuery Calculation plugin.
Code:
Sum:
And following is JQuery Code:
And following is error, displayed in FireBug:
Code:
Note: Table Sorter plugin works fine and it seems problem in calculation plugin.
View 6 Replies
View Related
Jun 29, 2005
I am really new to Javascript and I have mutteled trough this form and about the onyl thing I have left to do is to get the TOTAL to display in Currency format and not just 4356.548
It needs to look like this:
$4,356.55
View 4 Replies
View Related
Jun 18, 2011
I am a novice user of Expressions Web4 and am attempting to build a form that makes calculations of field entries and displays the results in designated fields. Specifically, multiplying the entry in the pmt_amt field by .03 and placing the result in the srv_fee field, then adding the entry in the pmt_amt field to the result in the srv_fee field to show the resulting sum in the total_pmt_amt field. I have created functions in JavaScript for both calculations and tied them to onClick relative to a button btn_srv_fee.
I used this method by searching online for an appropriate method and tweaked results for my application. Below is the code for what I am attempting to do. Upon making an entry in the pmt_amt field and then clicking the button, there are no results in neither the srv_fee field or total_amt_field. Below is the code for the functions and the associated section that identifies the fields.
<script type="text/javascript">
function multiplyNumbers(pmt_amt, .03, ResultField1)
{
[code]....
View 1 Replies
View Related
Nov 23, 2010
I have an input for Fahrenheit in degrees, then a button to start the calculations, then an input box for the result. But the result stays empty. where my Javascript code went wrong? I am modifying someone else's code form the Internet,I am guessing at how it works. [code]
View 4 Replies
View Related
Oct 20, 2009
I am currently working on a project where I am using the jQuery Calculation plugin [URL] to do some math functions in a dynamic form, the issue is that when a new set of fields is created the calculation script only pulls data from the ones there when the page loaded, I am fairly certain that what I need to do is use the live function, however I am not very familiar with it and still learning. My jQuery for the plugin is :
$("input[name^=emem]").sum("keyup", "#totalMem");
View 1 Replies
View Related