Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with simple script! 3

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
<br>
I am trying to write a script that will write the tag below<br>
<br>
&lt;IMG SRC="Image.gif" Width="XXX" Height="XXX" ID="PicID"&gt;<br>
<br>
What The script needs to do, is depending on the users input write the above tag replacing the XXX with particular numbers... <br>
<br>
Here is what I have so far... it is not working!<br>
<br>
&lt;script&gt;<br>
function ShowTheMap(e)<br>
{ <br>
If (e==""){<br>
ImgWidth="300";<br>
ImgHeight="280";<br>
}<br>
If (e=="1")<br>
{<br>
ImgWidth="450";<br>
ImgHeight="420";<br>
}<br>
If (e=="2")<br>
{<br>
ImgWidth="675";<br>
ImgHeight="630";<br>
}<br>
If (e=="3")<br>
{<br>
ImgWidth="1024";<br>
ImgHeight="945";<br>
}<br>
ThisString='&lt;IMG SRC="Image.gif" width="'+ImgWidth+'" Height="'+ImgHeight+'" ID="PicId"&gt;';<br>
document.write(ThisString);<br>
}<br>
&lt;/script&gt;<br>
<br>
<br>
And the script would (supposedly) be called like this:<br>
<br>
&lt;A Href="#" onClick="ShowTheMap()"&gt;X1&lt;/a&gt;<br>
&lt;A Href="#" onclick="ShowTheMap(1)"&gt;X2&lt;/a&gt;<br>
&lt;A Href="#" onclick="ShowTheMap(2)"&gt;X3&lt;/a&gt;<br>
&lt;A Href="#" onclick="ShowTheMap(3)"&gt;X4&lt;/a&gt;<br>
<br>

 
Unfortunatly the width and height values for images are read-only values. You can't write them once the page is loaded using JavaScript. You can set it up so that the page re-loads with the desired height and width values using CGI, or SSJS.
 
Actually, you can re-write image width and height values dynamically in IE4, and I believe IE5. We can only hope that soon Netscape will support it too, as I still tend to favor them. See my (soon to be replaced) home page at (If you doin't see the page described below, go to <br>
You will notice at the bottom of the page a small blue sphere which changes width repeatedly in IE4. Unfortunately the code is buried because I also used Macromedia Dreamweaver's Timeline function to animate a couple of layers after the sphere is clicked. If you view the code, look for 'MM_changeProp' and you will see Dreamweaver's way of doing it.<br>
<br>
Also, in answer to TheOrange; yes it can be done with CGI or server-side Javascript, but 'document.write' will accomplish it without reloading anything from the server. This method will work for both browser flavors.
 
Thank you rycamor, but unfrotunately I got very confused trying to read the code on your page. I did notice, however a call to image.length, which may be what I am needing to look at.
 
Actually, your script above is on the right track for at least one of the ways to do it; you just need to learn a little more about Javascript and HTML syntax, and what document.write actually does. Think of it this way: document.write used by itself simply rewrites the current contents of the HTML page with the strings and variables you define--it creates a new web page. <br>
<br>
Among the things to consider: the string you are trying to write above doesn't contain any of the header and footer tags that you need to define a full HTML page. (you can use document.write more than once in a script)<br>
<br>
Learn some more about the 'document' object itself, which provides more than one method for manipulating the current HTML document.
 
Wow, thanks rycamor, I'm a netscape user, and have been tending to ignore IE specific coding, I didn't know you could tweek them dynamicaly in IE.
 
I am not sure I follow you rycamor. I am using the document.write in my web page ( to put some text on the page, and haven't used any header or anything. Is there some isntances you can do this and some you can't?
 
I have used the document.write command to write entire web pages before. You write out a page template with a bottom and a top, and save each part as seperate .js files. In your main document you can write &lt;script language="JavaScript" src="top.js"&gt;then you write the main content here and enclose it with &lt;script language="JavaScript" src="bottom.js"&gt; and the same scripts can be used to write an entire web site, saving lots of time building tables, and all that kind of stuff, and since your website looks basically the same throught, it gives a chance to add unique themes to your pages which will be on every page. The only problem with this however, is some people may have older browsers, or may have their JavaScript disabled, in which case you would want to make sure you include the &lt;noscript&gt;&lt;/noscript&gt; tags with a little note in between reminding people to enable their JavaScript or upgrade their browser.
 
jvogel-<br>
<br>
Hmm... I would have to say yes. I didn't think about it before, but for the newer browsers you can render to just a part of the page. This must be because you place your script right INSIDE your table tags, without declaring a function, whereas most Javascript is declared as a function just after &lt;/head&gt;. I found this not to work in Netscape 3, though, so I don't know how recent this attribute is.<br>
<br>
caseyc is right, however server-side includes (SSI) can accomplish some of the functions you might be now doing with Javascript, and it can interact well with Javascript. For example, if you want a web page to include the contents of a text file inside ANY area of the HTML, &lt;!--#include file="info.txt" --&gt; would put whatever contents you have in info.txt inside any formatting tags in your HTML, at the moment the page is requested by the browser. (Needs .shtml extension and permission from server)
 
Yes, this is great for people that have access to a cgi directory, but for those who don't (and there are many) the JavaScript src attribute works great. However, I have recently discovered a bug in Netscape Navigator which conflicts with the script src attribute when there is more than one script src tag on a single page. If there is more than one script src tag on the page, then only the results of one sript src tag will appear on the page, or maybe one or more but the others will only partially apper, not in whole.
 
rycamor,<br>
<br>
Seems like SSI is pretty restrictive. Needing to use the extension .shtml and permissions from the server. Is there any reason to use this method over javascript? And which browsers support it?
 
I have run into trouble with SSI and Netscape Navigator,<br>
sometimes the poor little inferior browser just gets confused.
 
hmm....now that I think about it, there isn't anything little about Netscape...Anyway, another good thing about the JavaScript method is that discourages would-be-source-viewers/copier-stealers from looking at your code because you can remove all line breaks, so even if they do bother to view the remote JavaScript file, it is very difficult for them to read. Good for security purposes; just a thought.
 
He...he... at least it doesn't crash your system, or open the contents of your clipboard to malicious Javascripts.<br>
<br>
Yeah, Netscape is bloated at the moment. The open-source people working on the new one (mozilla.org) have pretty much scrapped the old rendering engine, saying they got more mileage out of it than anyone should have expected. There is some majorly cool stuff in the works, though, as far as customizability, javascript, CSS, etc...<br>
<br>
I can't help finding it a bit ironic that we're trashing Netscape in a forum about Javascript, which was created by Netscape.<br>
<br>
I fail to see how any browser could have trouble with SSI, since it happens BEFORE the browser even sees the code. But we go off-topic.<br>
<br>
Clever idea, removing line breaks.
 
Is there any way to do a server side include based on the result of an equation?<br>
<br>

 
what kind of equation? A CGI type of equation? If so, yes, it seems that server side includes may be integrated with shell like this:<br>
&lt;!--#set var="Zed" value="${REMOTE_HOST}_${REQUEST_METHOD}"--&gt;
 
You are right rycamor, it wasn't the SSI specifically which caused the problem, I just discovered, it was the fact that it was enclosed in an unterminated table cell, which was the result of splitting the table down the middle and saving it as two seperate .js files, so that I could write the content in between and have it be enclosed by the table. Theoretically this would work fine, and it does with Internet Explorer and other non-mozilla browsers, but Netscape Navigator sees the unterminated table cell and chokes on it, instead of completing the cell with the second .js file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top