Forum Moderators: open

Message Too Old, No Replies

new to JavaScript

passing values

         

boguslawa

6:40 pm on Oct 4, 2005 (gmt 0)

10+ Year Member



Hello,
I'm not a coder at all ...i'm trying to make a calculator with JS, i have an external js code with is included on my page ... the problem that i'm having is i wanted to know if i could have my js code grab the values from the one HTML page...calculate it but have the calculated value show on another HTML page? (does that make sense?)

when i try i get an error of a null value cause i'm calling a text box that is in my other HTML page

any guidence would me much appreciated ...thx

Bee

Dijkgraaf

9:07 pm on Oct 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Give us what code you have so far and we might be able to debug it.
How does the one page know about the other?
e.g. did one page open up the other one in a new window, or are they part of a frameset?

boguslawa

1:36 pm on Oct 5, 2005 (gmt 0)

10+ Year Member



well it all goes thru a form;

this is the js code

function numb(num)
{
return "$" + Math.round(num) + ".00";
}

function Calculate()
{

var total = document.Cal.numEmp.value * document.Cal.salary.value * document.Cal.daysWork.value * document.Cal.benLoad.value * document.Cal.empAbsence.value * document.Cal.lostPerEmp.value;

document.Cal.daysLostDay.value = numb(total);
}

The first form tells the code to work its function when you hit submit.

Than the daysLostDay is the value that i would want to be seen on the next form(on another html page).

If i used framesets would it would it work better?
Could i than have the froms work with the same js code?

I'm not using frame sets right now ...just two html pages with a new form on each (I have the same form name for both forms..thinking it would populate thru out cause i have my js as an external)

sorry if i'm blabbing ...i just don't understand what i'm doing wrong or not doing

Bee

Dijkgraaf

11:33 pm on Oct 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, you aren't telling us how these two "pages" are being opened.
If you open up two seperate browsers and open up each respective page then you will never get one to update the other.

Some ways of doing what you want are
1) You submit the data from one form via either a POST or a GET and the second page will load within the same browser window.
2) One of the pages is opened by the other via window.open() method and then you can either refer to it via the name you opened the new window with, or with window.opener (depending on which window is refering to the other).
3) The first page saves the data to somewhere and the second page loads the data from there.

It depends on what you are trying to achieve which will determine which of the above you should use.