Passing text to a new window

  • Thread starter BrendanMcPherson
  • Start date
B

BrendanMcPherson

Hi whats the easiest way to pass text from one page to another.

I have a form on one page that has a textbox and "go" button.
when the user selects Go, i would like it to go to another window
with the text he/she already inputed filled in the textbox.
 
D

darwinist

Hi whats the easiest way to pass text from one page to another.

I have a form on one page that has a textbox and "go" button.
when the user selects Go, i would like it to go to another window
with the text he/she already inputed filled in the textbox.

Try it for another page in your own domain first, then it will be easy
to see that you can't do it for someone else's site.
 
E

Erwin Moller

Hi whats the easiest way to pass text from one page to another.

I have a form on one page that has a textbox and "go" button.
when the user selects Go, i would like it to go to another window
with the text he/she already inputed filled in the textbox.

Hi,

The easiest way is to use a serverside language, like PHP.
If that is no option, just pass the text to the next page using the URL.

From your first page:
<form action="nextpage.html" METHOD="GET">
<input type="text" name="yourname">
<input type="button" value="go">
</form>

If somebody filled in "Joe Jackson", the URL will contain:
nextpage.html?yourname=Joe%20Jackson

From nextpage.html
<script type="text/javascript">
// get the passed value for yourname
var query = location.search.substring(1);
// query now contains yourname=Joe%20Jackson
// now do basic stringmanipulation to retrieve the actual name.

</script>


Regards,
Erwin Moller
 
B

BrendanMcPherson

Thanks Erwin,
thats great. thanks i thought that was the simplest.

do you know an even simpler way.
can you do it simple like this line
javascript:void(document.body.style.backgroundColor='#c00')
 
E

Erwin Moller

Thanks Erwin,
thats great. thanks i thought that was the simplest.

do you know an even simpler way.
can you do it simple like this line
javascript:void(document.body.style.backgroundColor='#c00')

Well yes.
If you have already 2 windows, you can use Javascript to communicate
directly (assuming the 2 windows are in the same domain).

eg from mainpage:
var myNewWindowRef = window.open(..etc..);

// call a function in new window:
myNewWindowRef.document.setName("John");

The last call tries to pass the string "John" directly to a function named
setName in the new window.
(Pay attention however that the second window must be fully loaded first
before the Javascriptfunctions become available, otherwise you'll get an
error of course because the function doesn't exist.)

Regards,
Erwin Moller
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,144
Latest member
KetoBaseReviews
Top