...

View Full Version : document.write a javascript:function() inline?



PhotoJoe47
10-19-2005, 03:14 AM
I'm back after giving up two years ago to write a page of html code with javascript in it.

I want to display a table with five images (tumbnails) per row with the name of the image (my code number for the image) under it. I want 4 rows of images for a total of 20 images (tumbnails).

I want when someone clicks on one of the tumbnail images a new window opens with the fullsize image displayed.

I have written an html page that does this but I have over 50 such pages that I need to create for my website. Here is the code that does this for each table image cell.

<td width="20%" height="116" valign="middle" align="center"><a
href="javascript:winopen('single_Slide.htm',arrSlidePaths[0])"><img
border="0" src="images/AK_Small/tn_AK020.jpg"
alt="AK020.jpg (39005 bytes)" width="100" height="66"></a></td>

But I have to change the data for every image cell in the table and for every page.

Now I have written a page where javascript code writes the the whole table in a nested for loop using document.write. I just have to change the value of the variables once at the top of the page in the head section. Here is a copy of that code.

<SCRIPT LANGUAGE="JavaScript">

var SizeH = '0';
var SizeW = '0';

for(row=0; row<=3; row++)
{
document.write("<tr>");
for(cell=0; cell<=4; cell++)
{
if(arrSize[cell + (row * 5)] == true)
{
SizeH = '67';
SizeW = '100';
}
else{
SizeH = '100';
SizeW = '67';
}

document.write("<td width='20%' height='116' valign='middle' align='center'>");
document.write("<href='javascript:winopen('single_Slide.htm',arrSlidePaths[cell + (row * 5)])'>");
document.write("<img border='1' src='images/Other/blank.gif' alt = 'Click here to see larger image'");
document.write("width=" + SizeW + "height=" + SizeH + "></a></td>");
}
document.write("</tr>");
document.write("<tr>");
for(cell=0; cell<=4; cell++)
{
document.write("<td width='20%' height='20' valign='bottom' align='center'><font face='Comic Sans MS' size='4' color='#CC3300'>" + arrSlideNumbers[cell + (row * 5)] + "</font></td>");
}
document.write("</tr>");
}
</script>

All the tumbnail images are there (I have an onload function that changes the blank.gif images to my tumbnail images) and so are the names but when I try to click on any of the tumbnail images it does not display the fullsize image.

I think the problem is in this part of the javascript:

document.write("<href='javascript:winopen('single_Slide.htm',arrSlidePaths[cell + (row * 5)])'>");

I don't think I can call a javascript function from within a document.write function? If you can I just don't know the correct syntax.

Maybe someone can tell me a better way to do this?

Thanks,
PhotoJoe

Kor
10-19-2005, 08:09 AM
document.write("<href=\"javascript:winopen('single_Slide.htm',arrSlidePaths[cell + (row * 5)])\">");

You must use escape to insert quotes in a string, in case the quote type is the same with the string's construction.

glenngv
10-19-2005, 08:39 AM
document.write('<a href="javascript:winopen(\'single_Slide.htm\', ' + arrSlidePaths[cell + (row * 5)] + ')">');

Kor
10-19-2005, 08:40 AM
eeerr, yes, I haven't noticed this one...

PhotoJoe47
10-19-2005, 04:25 PM
Thanks KOR and Glenn.

That fix it. Now I get the new window in the mainpage of my frame. But I get the little white box with the red x.

So I'm not passing the correct path of the larger image.

After pluging in constant path which work and then pluging in a variable with a constant index I have come to the conclusion that this part of the line of code does not work:

arrSlidePaths[cell + (row * 5)])\">");

So why does the math function not work inside a document.write function?

Thanks,
PhotoJoe

Kor
10-19-2005, 04:28 PM
well, hm... if a significan bounch of HTML tags are to be dynamically created/modified on the page (along with events and so on) I suggest you to use DOM methods instead of the deprecated document.write() method.

PhotoJoe47
10-19-2005, 04:40 PM
well, hm... if a significan bounch of HTML tags are to be dynamically created/modified on the page (along with events and so on) I suggest you to use DOM methods instead of the deprecated document.write() method.

Thanks KOR.

I don't know anything about DOM. Could you give me little help with this? Give me a starting point on what I'm trying to do and maybe a reference link so I can learn the syntax of the code.

BTW how do you insert those neat code boxes inside these messages? I have look all over for instruction on how to do it, but so far I most be looking in all the wrong places :)

Thanks,
PhotoJoe

Kor
10-19-2005, 04:46 PM
http://developer.apple.com/internet/webcontent/dom2i.html

PhotoJoe47
10-19-2005, 10:20 PM
Ok Guys,

I have been playing around with the document.write() function some more. Here is what I see that is going on.

document.write("<a href=\"javascript:winopen('../single_Slide.htm',arrSlidePaths[cell + (row * 5)])\">");

First the second argument in the winopen() function causes and undefine error. It seems that if I put a variable in the [] for the the arrSlidePaths array variable it will give the undefine error. But if I put a actual number like 0 or 1 it will work and past the correct path for that one image. Now if I put the following code in front of the document.write() function like this:

Path1 = cell + (row * 5);
.
.
document.write("<a href=\"javascript:winopen('../single_Slide.htm',Path1)\">");
.
.

The Path1 variable gets pasted to the winopen() function.

I changed my winopen() to the following code:

function winopen(NewPage,Path)
{
document.write(NewPage);
document.write(Path);
//parent.contents.Store = Path;
//newwin=window.open(NewPage,"main")
}

I did this so I could see what was being past to the function. It seems that when I use the Path1 variable in the code that calls the winopen() function it passes the the last value of Path1 which is 19 no matter which tumbnail image I click on. If I use an array variable with a variable index I get undefine.

I think this means that the address of the variable and not the content of the variable is beings passed to the winopen() function.

That is the problem as I see it, so how do fix this so that I can pass the path of the image to the winopen() function?

Thanks,
PhotoJoe

glenngv
10-20-2005, 02:35 AM
I have mistaken the array arrSlidePaths for arrSize which is an array of boolean.
I thought they are the same, that's why in my previous post, I didn't put quotes around the 2nd parameter of winopen() method.


document.write('<a href="javascript:winopen(\'single_Slide.htm\', &quot;' + arrSlidePaths[cell + (row * 5)] + '&quot;)">');

I could have put \' instead of &quot; but filenames can contain single quotes, so the path would be messed up. So I have to put " but it's needed to be HTML-encoded to not clash with the " in the attribute.

BTW, regarding your question about putting post in boxes. You need to wrap the content in
tags or just use the # icon.

PhotoJoe47
10-20-2005, 10:02 AM
Thanks Glenn,

I'm learning from your posts.

At first I didn't think is was working. I was just trying to see if the links work using the preview tab of FrontPage2000. It kept giving me an error message that 'parent.contents' was null are not an object. I forgot I needed to start from the index page where the frame for my pages was created.

Again thanks bunches @===== @=====

PhotoJoe

tmmails
10-29-2005, 12:59 PM
How to find a IP address of Particular Website address in Java script?

Pls Advise!!

PhotoJoe47
10-29-2005, 04:26 PM
How to find a IP address of Particular Website address in Java script?

Pls Advise!!

I don't understant your question, does it have something to do with what has beening going on in this message thread?

You might get a better response if you posted a new message and explain what you are trying to do.

PhotoJoe



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum