By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,384 Members | 1,794 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,384 IT Pros & Developers. It's quick & easy.

Passing a URL as a parameter does not appear to work

P: n/a
Hi All

Very new to web page design here. Week 1 in fact.

I have a javascript function that is called in an OnClick event for a
button.
I am attempting to get the function to open a web page in a new window
in response to a button click.

I can get the page to open if I use the following syntax (hard code the
address)

var newwin =
indow.open("http://www.w3schools.com","","width=1200height=1000");

However, If I pass the url in as a parameter to the function (as below)
the value passed in is "Undefined" and obviously the page will not open

function openThePage(url)
{ url = "http://www." + url;
var newwin = window.open(url,"","width=1200height=1000");
}

<input
class="mybutton"
type="button"
name = "W3Schools"
value="w3schools.com"
onclick="openMyUrl(W3Schools.Value)">
&nbsp;&nbsp;

Anyone any idea how I can do what I want - what I am doing wrong. I am
grey enough as it is and I don't want to start pulling my hair out.

Thanks for help offered

Iain

Oct 9 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Em**************@gmail.com wrote:

Very new to web page design here. Week 1 in fact.
Week 1 and you're on JavaScript already?! I wouldn't advise touching it
until you had mastered HTML and become proficient with CSS.
I am attempting to get the function to open a web page in a new window
in response to a button click.
Oh dear. Foisting new windows on users is a very bad idea at least 99% of
the time.
I can get the page to open if I use the following syntax (hard code the
address) var newwin =
indow.open("http://www.w3schools.com","","width=1200height=1000");
I'm assuming you accidently dropped the "w" from the start and you actually
have a comma in that last bit. That's a huge window though, it won't fit on
most screens.
However, If I pass the url in as a parameter to the function (as below)
the value passed in is "Undefined" and obviously the page will not open <input
class="mybutton"
type="button"
name = "W3Schools"
value="w3schools.com"
onclick="openMyUrl(W3Schools.Value)">


What is "W3Schools"? Most browsers do not create global variables with a 1:1
correspondence to any element with a name, and I think that the "Value"
property is case-sensitive (and all lower-case) anyway.

onclick="openMyURL(this.value);"

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Oct 9 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.