Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > Variable Replacement in HTML

Reply
Thread Tools

Variable Replacement in HTML

 
 
Bill Burke
Guest
Posts: n/a
 
      09-17-2006
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,locat ion=no,directories=no,
status=no,menubar=no,scrollbars=no,resizable=no,le ft=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


 
Reply With Quote
 
 
 
 
Neredbojias
Guest
Posts: n/a
 
      09-18-2006
To further the education of mankind, Bill Burke
<> vouchsafed:

> 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,locat ion=no,directories=no
> , status=no,menubar=no,scrollbars=no,resizable=no,le ft=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.

--
Neredbojias
Infinity has its limits.
 
Reply With Quote
 
 
 
 
Toby Inkster
Guest
Posts: n/a
 
      09-18-2006
Bill Burke wrote:

> <td height="19" width="338"><a href="#" onClick="MyWindow=window.open($bigPIC
> ,'MyWindow',$bigWIDTH,$bigHEIGHT,'toolbar=no,locat ion=no,directories=no,
> status=no,menubar=no,scrollbars=no,resizable=no,le ft=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+',toolb ar=no,location=no,');
document.write('directories=no,status=no,menubar=n o,scrollbars=no,');
document.write('resizable=no,left=100,top=100\');r eturn 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.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

 
Reply With Quote
 
Jonathan N. Little
Guest
Posts: n/a
 
      09-18-2006
Toby Inkster wrote:

> 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...

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
 
Reply With Quote
 
Mr Squiddy
Guest
Posts: n/a
 
      09-18-2006
Jonathan N. Little wrote:
> Toby Inkster wrote:
>
>> 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...
>

Yeah. The boy done good.
 
Reply With Quote
 
Leif K-Brooks
Guest
Posts: n/a
 
      09-18-2006
Toby Inkster wrote:
> 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
 
Reply With Quote
 
Michael Winter
Guest
Posts: n/a
 
      09-18-2006
Leif K-Brooks wrote:

> Toby Inkster wrote:
>> Firstly, Javascript variables cannot begin with a dollar sign.

>
> 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
 
Reply With Quote
 
Jonathan N. Little
Guest
Posts: n/a
 
      09-18-2006
Leif K-Brooks wrote:
> Toby Inkster wrote:
>> 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


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.

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using variable in replacement expression RobV Perl Misc 4 08-11-2012 07:25 AM
Need direction on mass find/replacement in HTML files KevinUT Python 3 05-01-2010 10:57 PM
"Variable variable name" or "variable lvalue" mfglinux Python 11 09-12-2007 03:08 AM
aspx variable replacement - runat=server testemail@skunkbox.com ASP .Net 3 01-28-2005 04:06 PM
How do I scope a variable if the variable name contains a variable? David Filmer Perl Misc 19 05-21-2004 03:55 PM



Advertisments