Page 1 of 1

Simple Javascript Help

Posted: Tue Nov 23, 2010 11:37 am
by spacebiscuit
Hi guys,

I code in PHP but can't figure out a simple bit of javascript! I want to use variables for a popup script:

Code: Select all

<script language="JavaScript">
function popup(pagename){
window.open(pagename.'.php','popjack','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=no,scrollbars=yes,width=427,height=400');}
</script>
The HTMl to call the javascript

Code: Select all

<a href="JavaScript: popup(pagename)">terms and conditions</a>
I'm obviusly doing what I would if I was coding in PHP - what am I missing?

Thanks,

Rob.

Re: Simple Javascript Help

Posted: Tue Nov 23, 2010 1:06 pm
by McInfo
In JavaScript, plus (+) is the concatenation operator.

Re: Simple Javascript Help

Posted: Tue Nov 23, 2010 3:04 pm
by spacebiscuit
Ok thanks - I have changed that.

Now I am getting an error which says the parameters is undefined:

for example:

Code: Select all

<a href="JavaScript: popup(pagename)">
The error says that 'pagename' is undefinted.

Thanks in advance,

Rob.

Re: Simple Javascript Help

Posted: Tue Nov 23, 2010 3:54 pm
by McInfo
Replace pagename with something else, like a variable that is defined or a string.

Code: Select all

popup('index');

Re: Simple Javascript Help

Posted: Tue Nov 23, 2010 6:36 pm
by spacebiscuit
Perfect thans, I just had to add the quotations to cast the paramater as a string.

Your help is appreciated.

Rob.