Variable Replacement in HTML

Discussion in 'HTML' started by Bill Burke, Sep 17, 2006.

  1. Bill Burke

    Bill Burke Guest

    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
     
    Bill Burke, Sep 17, 2006
    #1
    1. Advertising

  2. Bill Burke

    Neredbojias Guest

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

    --
    Neredbojias
    Infinity has its limits.
     
    Neredbojias, Sep 18, 2006
    #2
    1. Advertising

  3. Bill Burke

    Toby Inkster Guest

    Bill Burke wrote:

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

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, Sep 18, 2006
    #3
  4. 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
     
    Jonathan N. Little, Sep 18, 2006
    #4
  5. Bill Burke

    Mr Squiddy Guest

    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.
     
    Mr Squiddy, Sep 18, 2006
    #5
  6. 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
     
    Leif K-Brooks, Sep 18, 2006
    #6
  7. 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
     
    Michael Winter, Sep 18, 2006
    #7
  8. 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
     
    Jonathan N. Little, Sep 18, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    5,046
  2. mfglinux
    Replies:
    11
    Views:
    726
    Roberto Bonvallet
    Sep 12, 2007
  3. KevinUT
    Replies:
    3
    Views:
    322
    Novocastrian_Nomad
    May 1, 2010
  4. RobV
    Replies:
    4
    Views:
    445
    C.DeRykus
    Aug 11, 2012
  5. Replies:
    4
    Views:
    216
    Rainer Weikusat
    May 2, 2013
Loading...

Share This Page