Variable Replacement in HTML

B

Bill Burke

Hello,

I am trying to use variable replacement to define the size of a web page. I have
pasted the single line of code below - variable $bigPIC works, but $bigWIDTH and
$bigHEIGHT don't.

<td height="19" width="338"><a href="#" onClick="MyWindow=window.open($bigPIC
,'MyWindow',$bigWIDTH,$bigHEIGHT,'toolbar=no,location=no,directories=no,
status=no,menubar=no,scrollbars=no,resizable=no,left=100,top=100'); return
false;">&gt; click here for a larger view &lt;</a></td>

I am setting the value for the three variables in the javascript portion of the
HMTL page:

var $bigPIC="images/big_bock.jpg"
var $bigWIDTH="width=530px"
var $bigHEIGHT="height=435px"

-then-
if(cImg==1)
{
var bTextMode=false
$bigPIC="images/big_bock.jpg"
$bigWIDTH="width=530px"
$bigHEIGHT="height=435px"
....more stuff}

-then_
if(cImg==2)
{
$bigPIC="images/big_bock_2.jpg"
$bigWIDTH="width=380px"
$bigHEIGHT="height=738px"
....more stuff}

etc....

Any help and suggestions will be greatly appreciated.

Thanks in advance,
Bill Burke
(e-mail address removed)
 
N

Neredbojias

To further the education of mankind, Bill Burke
Hello,

I am trying to use variable replacement to define the size of a web
page. I have pasted the single line of code below - variable $bigPIC
works, but $bigWIDTH and $bigHEIGHT don't.

<td height="19" width="338"><a href="#"
onClick="MyWindow=window.open($bigPIC
,'MyWindow',$bigWIDTH,$bigHEIGHT,'toolbar=no,location=no,directories=no
, status=no,menubar=no,scrollbars=no,resizable=no,left=100,top=100');
return false;">&gt; click here for a larger view &lt;</a></td>
....


Your window.open attribute line is wrong. There are 3 discrete sections at
most - separated by commas; if using variables, you might need to
concetate.
 
T

Toby Inkster

Bill said:
<td height="19" width="338"><a href="#" onClick="MyWindow=window.open($bigPIC
,'MyWindow',$bigWIDTH,$bigHEIGHT,'toolbar=no,location=no,directories=no,
status=no,menubar=no,scrollbars=no,resizable=no,left=100,top=100'); return
false;">&gt; click here for a larger view &lt;</a></td>

I am setting the value for the three variables in the javascript portion of the
HMTL page:

var $bigPIC="images/big_bock.jpg"
var $bigWIDTH="width=530px"
var $bigHEIGHT="height=435px"

Ummm... that's not at all how Javascript works.

Firstly, Javascript variables cannot begin with a dollar sign. Should be:

var bigPIC="images/big_bock.jpg";
var bigWIDTH="width=530px";
var bigHEIGHT="height=435px";

Secondly, you can't then drop them into some HTML and expect them to do
something -- Javascript variables only "have scope" within script blocks.
So you want something like:

<script type="text/javascript">
document.write('<td height="19" width="338">');
document.write('<a href="'+bigPIC+'" target="MyWindow" ');
document.write('onClick="MyWindow=window.open(this.href, this.target, ');
document.write('\''+bigWIDTH+','+bigHEIGHT+',toolbar=no,location=no,');
document.write('directories=no,status=no,menubar=no,scrollbars=no,');
document.write('resizable=no,left=100,top=100\');return false;">')
document.write('&gt; larger view &lt;</a></td>');
</script>

Lastly, depending on how you calculated the value for "cImg" this would
probably be better/easier using server-side scripting.
 
J

Jonathan N. Little

Toby said:
Firstly, <snip>
Secondly, <snip>
Lastly, <snip>

Hooray for Toby! Pet peeve of mine, to rally against the demise of the
adverb in modern English! Really good to see...
 
M

Mr Squiddy

Jonathan said:
Hooray for Toby! Pet peeve of mine, to rally against the demise of the
adverb in modern English! Really good to see...
Yeah. The boy done good.
 
L

Leif K-Brooks

Toby said:
Firstly, Javascript variables cannot begin with a dollar sign.

Yes, they can; it's just not a very good idea in most cases. The
ECMAScript spec says:

IdentifierName ::
IdentifierStart
IdentifierName IdentifierPart
IdentifierStart ::
UnicodeLetter
$
_
UnicodeEscapeSequence
IdentifierPart ::
IdentifierStart
UnicodeCombiningMark
UnicodeDigit
UnicodeConnectorPunctuation
UnicodeEscapeSequence
 
M

Michael Winter

Leif said:
Yes, they can; it's just not a very good idea in most cases.

Indeed:

The dollar sign ($) and the underscore (_) are permitted
anywhere in an identifier. The dollar sign is intended for use
only in mechanically generated code.
-- 7.6 Identifiers, ECMA-262, 3rd Ed.

and there's no reason not to follow that convention.

Mike
 
J

Jonathan N. Little

Leif said:
Yes, they can; it's just not a very good idea in most cases. The
ECMAScript spec says:

IdentifierName ::
IdentifierStart
IdentifierName IdentifierPart
IdentifierStart ::
UnicodeLetter
$
_
UnicodeEscapeSequence
IdentifierPart ::
IdentifierStart
UnicodeCombiningMark
UnicodeDigit
UnicodeConnectorPunctuation
UnicodeEscapeSequence

Very true, but man can you really mess yourself up when building the
page with PHP or Perl! You technically can but I would highly recommend
that you don't.
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top