window.open - url variable ?

R

R45six

Really can't figure this out, would appreciate some help...

Have a textbox in a form which user types in a url link.

When they click a button I'd like it to open a new window,
and attempt to display the link they've typed in the textbox.

I've got the button calling a javascript with onclick,
but I can't get the window that opens to accept the dynamic url.

The textbox name is txtlink.

var thelink = txtlink.value;
testlinkwindow = window.open();

Is there a way to get the variable as the url parameter of open() ?

The other thing I've tried is setting the location.href of the child window,
but that doesn't work either. :-(

eg
testlinkwindow = window.open();
testlinkwindow.location.href= txtlink.value;

Please can you help ?
R.
 
R

Randy Webb

R45six said:
Really can't figure this out, would appreciate some help...

Have a textbox in a form which user types in a url link.

When they click a button I'd like it to open a new window,
and attempt to display the link they've typed in the textbox.

I've got the button calling a javascript with onclick,
but I can't get the window that opens to accept the dynamic url.

The textbox name is txtlink.

var thelink = txtlink.value;
testlinkwindow = window.open();


var thelink = document.forms['formname'].elements['txtlink'].value
window.open (thelink)
 
G

GreenLight

R45six said:
Really can't figure this out, would appreciate some help...

Have a textbox in a form which user types in a url link.

When they click a button I'd like it to open a new window,
and attempt to display the link they've typed in the textbox.

I've got the button calling a javascript with onclick,
but I can't get the window that opens to accept the dynamic url.

The textbox name is txtlink.

var thelink = txtlink.value;
testlinkwindow = window.open();

Is there a way to get the variable as the url parameter of open() ?

Have you tried actually passing it as the URL parameter? You don't
have any parameters to open() in the posted code.

Have a look here:

http://www.mozilla.org/docs/dom/domref/dom_window_ref76.html#1019331
 
R

R45six

var thelink = document.forms['formname'].elements['txtlink'].value
window.open (thelink)

Cheers, couldn't get it accept a variable inside the brackets.

I think it was also a problem, not naming the form.

Ended up with this.

var thelink = formname.txtlink.value
window.open("" + thelink)
 
R

Randy Webb

R45six said:
var thelink = document.forms['formname'].elements['txtlink'].value
window.open (thelink)


Cheers, couldn't get it accept a variable inside the brackets.

I think it was also a problem, not naming the form.

Ended up with this.

var thelink = formname.txtlink.value
window.open("" + thelink)


var myVar = "txtlink";
document.forms['formName'].elements[myVar].value;

you have to drop the quotes inside the brackets when using a variable.
 

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

Similar Threads

window.open 13
window.open problem 5
window.open 2
variable in window.open function 3
Getting value of instances of variable. 1
window.open 1
pass url to a popup 6
window.open question 1

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top