Passing a URL as a parameter does not appear to work

  • Thread starter Email.IainWilson
  • Start date
E

Email.IainWilson

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
 
D

David Dorward

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);"
 

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
474,433
Messages
2,571,683
Members
48,796
Latest member
Greg L.

Latest Threads

Top