You are here: Re: Variable Replacement in HTML « HTML « IT news, forums, messages
Re: Variable Replacement in HTML

Posted by Toby Inkster on 11/25/07 11:58

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация