Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sending the result of a javascript calculator to another page 1

Status
Not open for further replies.

Kirderf

Technical User
Oct 4, 2000
183
US
Can you take the result of a javascript calculation that displays in a text input box and send it to a form on another page?

And...are there any tutorials on this you could kindly point me to?

I'd gladly pay you on Thursday
for a hamburger today!
 
1) yes, you can.
2) i'm sure there are.

back to (1), here's a basic example:

main page:
Code:
<form name="f1">
  <input type="text" name="t" />
  <a href="#" onclick="window.open('[URL unfurl="true"]http://www.page.com/page.html');[/URL] return false;">Click To Fill Text Box</a>
</form>

on page.html:
Code:
<script language="javascript"><!--
function doCalc() {
   var theVal = 3 + 2;
   opener.forms['f1'].elements['t'].value = theVal;
   window.close();
}
--></script>



<a href="#" onclick="doCalc(); return false;">Click Me</a>

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
I created two pages.
new1.htm and new2.htm
New1.htm with this code for the body:
<body>
<form name="f1">
<input type="text" name="t" />
<a href="#" onclick="window.open(' return false;">Click To Fill Text Box</a>
</form>

</body>

The other, new2.htm code was this code:
<body><script language="javascript"><!--
function doCalc() {
var theVal = 3 + 2;
opener.forms['f1'].elements['t'].value = theVal;
window.close();
}
--></script>



<a href="#" onclick="doCalc(); return false;">Click Me</a>
</body>

Do you see what I am missing? I am really new to this as you might notice.


I'd gladly pay you on Thursday
for a hamburger today!
 
Yeah, I see what you're doing wrong. You're taking my advice. :) Sorry, I left one thing out. The relevant line of code should be:

Code:
opener[red].document[/red].forms['f1'].elements['t'].value = theVal;

And additionally, it is good practice to put <script> ... </script> between your <head></head> tags.

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
I am still getting the same thing. Nothing.
Forgive my rather simple quesitons, but...should I be adding anything where the # href is?

I did replace the opener.forms['f1'].elements['t'].value = theVal;

With

opener.document.forms['f1'].elements['t'].value = theVal;
and added my javascript to the head tags on page two.

I'd gladly pay you on Thursday
for a hamburger today!
 
works perfectly for me in both IE and Firefox.

new1.html:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]

<html>
<head>
<title>Untitled</title>
</head>

<body>

<form name="f1">
  <input type="text" name="t" />
  <a href="#" onclick="window.open('new2.html'); return false;">Click To Fill Text Box</a>
</form>

</body>
</html>

new2.html:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]

<html>
<head>
<title>Untitled</title>

<script language="javascript"><!--
function doCalc() {
   var theVal = 3 + 2;
   opener.document.forms['f1'].elements['t'].value = theVal;
   window.close();
}
--></script>

</head>

<body>

<a href="#" onclick="doCalc(); return false;">Click Me</a>

</body>
</html>

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Awesome! I think it was working the first time, but I didn't test it in anything other than this dern AOL.

When I went into ie it worked like a charm!

Thanks for sticking with me on this one cLFlaVa!

I greatly appreciate the information and I am a better programmer now! We must go celebrate a victory!

Yeeeessssss!

I'd gladly pay you on Thursday
for a hamburger today!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top