[thelist] Two Javascript problems
Warden, Matt
mwarden at odyssey-design.com
Sat Sep 16 17:46:21 CDT 2000
> To Whom it May Concern,
I guess that includes me.
> I have written a Javascript/HTML program which takes input from the
> user in a browser window, does some calculations, and then returns the
> results in an alert box. I need to be able to have these same results
> displayed in a separately opened browser window. Does anyone know how
> I can do this, i.e. via Javascript?
There are any number of ways you can do this. You can use
window.opener.getMyVariableValue() methods, or you can simply append the
values to the querystring like this:
displaypage.htm?target=evolt&isSexy=true&internet=cafe&isEndOfExampleURL=tru
e
and then parse out the values with Javascript on the newly-opened window.
You could then write these values to the document, or alert them, or
whatever else you can do with normal JS variables.
> Another thorny little problem: the numerical results come out
> expressed to lots of decimal places. I need to know some way in Java-
> script of rounding 3.141592654 (for example) into merely 3.14.
Math.round()? I believe it rounds to the nearest whole number, so:
(Math.round(3.141592654 * 100)/100)
Will get you the number rounded to the nearest hundreth. For those who fear
math like my uncle bob in a speedo, here's what's going on:
3.141592654 * 100 evaluates to 314.1592654
When Math.round() is called on 314.1592654 it will round it to the nearest
whole number, in this case, 314. So, now we undo our multiplication by
dividing by the same number (100) and we get:
3.14
which is exactly what we want.
HTH,
--
mattwarden
mattwarden.com
More information about the thelist
mailing list