/    Sign up×
Community /Pin to ProfileBookmark

dynamic url for window.open

Hi,

Iam having a problem in assigning a dynanic url to window.open function.

My page has the below:
Input textbox where user will enter the IP and a href link next to the textbox.

My code should do the following
Collect the IP address entered by user from the Input textbox and when the link is clicked open a new window with that IP as shown…. http://<ip>

In my HTML,
<input type=”text” name=”IP Address2″ size=”16″ class=control>
<A href=”javascript?penURL()” >
<font face=Arial size=2 color=”blue” >
<U><B>Open this Webpage</B></U>
</font>
</A>

In Javascript code,
function OpenURL()
{

var url=’http://192.168.5.66‘;
alert(url);
window.open(url,’open_window’,’location=yes,resizable=yes,dependent=yes,width=500,height=380,left=0,top=0′);
}

When the url is hardcodded as above, it works fine… but the below code does not

function OpenURL()
{
var ip = document.getElementById(‘IP Address2’).value;
alert(ip); // here the ip shows fine ex:192.168.5.66
var url=”http://”+ ip;
alert(url); // here url fine ex:[url]http://192.168.5.66[/url]
window.open(‘url’,’open_window’,’location=yes,resizable=yes,dependent=yes,width=500,height=380,left=0,top=0′);
}
but the popup window does not open to the correct url.

can anyone guide where i maybe going wrong?

Thanks in advance
Queenie

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@speghettiCodeMay 19.2009 — Have you tried removing the quotes around "url":

[CODE]('url','open_window','location=yes,resizable=yes,dependent=yes,width=500,height=380,left= 0,top=0')[/CODE]

to:

[CODE](url,'open_window','location=yes,resizable=yes,dependent=yes,width=500,height=380,left= 0,top=0')[/CODE]
Copy linkTweet thisAlerts:
@Queen245authorMay 19.2009 — One correction...

My code is as below:

function OpenURL()

{

alert("open URL");

var ip ="192.168.5.66";

//var ip = document.getElementById('IP Address2').value;

alert(ip); // here the ip shows fine ex:192.168.5.66

var url="http://"+ ip;

alert(url); // here url fine ex:http://192.168.5.66

window.open('url','open_window','location=yes,resizable=yes,dependent=yes,width=500,height=380,left= 0,top=0');

}

***********speghettiCode thanks!

Removing the quotes around "url" as suggested has solved a prt of the issue. Now the page opens to the right url.. but the url is still hardcodded.

Now only the task of assigning variable IP to the value entered by user in textbox is remaining,

is there a special way to accomplish this?
Copy linkTweet thisAlerts:
@speghettiCodeMay 19.2009 — For this part, you're asking for it to go out and "get an element by an ID" but you don't give the element an ID of the same value.

Try this:

[CODE]<input type="text" id='IP_Address2' name="IP_Address2" size="16" class=control>[/CODE]

and then...

[CODE]var ip = document.getElementById('IP_Address2').value;[/CODE]
Copy linkTweet thisAlerts:
@Queen245authorMay 21.2009 — Hi,

Thanks a ton.. speghettiCode!!! That did work.

Cheers!!

Queenie
×

Success!

Help @Queen245 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...