Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Regular Coder
    Join Date
    Oct 2005
    Location
    Arizona
    Posts
    336
    Thanks
    0
    Thanked 0 Times in 0 Posts

    document.write a javascript:function() inline?

    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

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Code:
    document.write('<a href="javascript:winopen(\'single_Slide.htm\', ' + arrSlidePaths[cell + (row * 5)] + ')">');
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    eeerr, yes, I haven't noticed this one...
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    Regular Coder
    Join Date
    Oct 2005
    Location
    Arizona
    Posts
    336
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #7
    Regular Coder
    Join Date
    Oct 2005
    Location
    Arizona
    Posts
    336
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Kor
    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

  • #8
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #9
    Regular Coder
    Join Date
    Oct 2005
    Location
    Arizona
    Posts
    336
    Thanks
    0
    Thanked 0 Times in 0 Posts

    argument for function is read as undefined

    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

  • #10
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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.

    Code:
    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 [code] [/code] tags or just use the # icon.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #11
    Regular Coder
    Join Date
    Oct 2005
    Location
    Arizona
    Posts
    336
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #12
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    IP Address

    How to find a IP address of Particular Website address in Java script?

    Pls Advise!!

  • #13
    Regular Coder
    Join Date
    Oct 2005
    Location
    Arizona
    Posts
    336
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tmmails
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •