Development document.write, IMG SRC and a variable

Discussion in 'Software' started by bushd, 25 Dec 2002.

  1. bushd

    bushd What's a Dremel?

    Joined:
    9 Nov 2002
    Posts:
    241
    Likes Received:
    0
    Alright, the code I have put together, let us not forget, I know little java, and this is peice together from trial/error/tutorials, and my wanting knowledge to use C++ into this for some ungodly reason.

    My problem is I cannot get the Image to show up as the picture. Anyone know a fix for that, or what I am doing wrong?

    <FONT onClick='openpicture("JamesAndAshlingHomecomming.jpg")'>James And Ashling</FONT>

    <SCRIPT LANGUAGE="JavaScript">
    function openpicture(image)
    {
    var image;
    OpenWindow=window.open("", "newwin", "height=250, width=250, toolbar=no, scrollbars=no, menubar=no");
    OpenWindow.document.write("<TITLE>Picutre Description</TITLE>")
    OpenWindow.document.write("<BODY BGCOLOR=#003366 TEXT=#CCCCFF LINK=#CCCCFF VLINK=#CCCCFF ALINK=#CCCCFF>")
    OpenWindow.document.write("<IMG SRC=image>")
    OpenWindow.document.write("<CENTER><FONT onClick='window.close()'> Click here to close </FONT></CENTER>")
    OpenWindow.document.write("</BODY>")
    OpenWindow.document.write("</HTML>")

    OpenWindow.document.close()
    self.name="main"
    }
     
  2. hydrogen18

    hydrogen18 Banned

    Joined:
    19 Jun 2002
    Location:
    black hole-----1337: yes
    Posts:
    1,861
    Likes Received:
    0
    im no JS expert...but i did notice that the window opened has an image with "image" in the filename
     
  3. bushd

    bushd What's a Dremel?

    Joined:
    9 Nov 2002
    Posts:
    241
    Likes Received:
    0
    Yes, that is where that variable is supposed to be, but how to place it there is beyond me.
     
  4. linear

    linear Minimodder

    Joined:
    5 Oct 2001
    Location:
    U S A
    Posts:
    4,393
    Likes Received:
    1
    For readability, I usually do something like:

    var Imagestring = "<IMG SRC=" + image;
    OpenWindow.document.write(Imagestring)


    The alternative (which you see much more frequently) is to do the plus bit to concatenate right inside the function call, I just find that less tidy.
     
  5. relix

    relix Minimodder

    Joined:
    14 Nov 2001
    Location:
    51° 20' 2", 3° 17' 35"
    Posts:
    5,948
    Likes Received:
    41
    Linear means like this:

    OpenWindow.document.write("<IMG SRC=" + image + ">");

    if you don't want to declare a new variable ;)


    also don't forget the ";" behind every line :D
     
  6. bushd

    bushd What's a Dremel?

    Joined:
    9 Nov 2002
    Posts:
    241
    Likes Received:
    0
    Thanks, will try that in a minute, I hand did that code above for every picture, I hope this works.
     
  7. bushd

    bushd What's a Dremel?

    Joined:
    9 Nov 2002
    Posts:
    241
    Likes Received:
    0
    When I click the text, I get:

    "Line: 0"
    "Error: Object expected"

    Anyone make sense of that?



    <FONT onClick='picture("JamesAndAshlingHomecomming")'>James And Ashling</FONT>

    <SCRIPT LANGUAGE="JavaScript">
    function picture(image)
    {
    var Imagestring = "<IMG SRC=./images/" + image + ".jpg";
    OpenWindow.document.write(Imagestring);
    OpenWindow=window.open("", "newwin", "height=250, width=250, toolbar=no, scrollbars=no, menubar=no");
    OpenWindow.document.write("<TITLE>Picutre Description</TITLE>");
    OpenWindow.document.write("<BODY BGCOLOR=#003366 TEXT=#CCCCFF LINK=#CCCCFF VLINK=#CCCCFF ALINK=#CCCCFF>");
    OpenWindow.document.write(Imagestring);
    OpenWindow.document.write("<CENTER><FONT onClick='window.close()'> Click here to close </FONT></CENTER>");
    OpenWindow.document.write("</BODY>");
    OpenWindow.document.write("</HTML>");

    OpenWindow.document.close();
    }
     
  8. 19nine78

    19nine78 What's a Dremel?

    Joined:
    11 Dec 2002
    Location:
    ayr
    Posts:
    18
    Likes Received:
    0
    change

    Code:
    OpenWindow.document.write(Imagestring);
    OpenWindow=window.open("", "newwin", "height=250, width=250, toolbar=no, scrollbars=no, menubar=no");
    
    to

    Code:
    OpenWindow=window.open("", "newwin", "height=250, width=250, toolbar=no, scrollbars=no, menubar=no");
    OpenWindow.document.write(Imagestring);
    
    Can't write into it until you've created it. :D

    cheers

    alastair
     
  9. bushd

    bushd What's a Dremel?

    Joined:
    9 Nov 2002
    Posts:
    241
    Likes Received:
    0
    Made the changes, still same error.
     
  10. 19nine78

    19nine78 What's a Dremel?

    Joined:
    11 Dec 2002
    Location:
    ayr
    Posts:
    18
    Likes Received:
    0
    you sure:confused: works ok for me.

    you also need to put a closing '>' on the line
    Code:
    var Imagestring = "<IMG SRC=./images/" + image + ".jpg";
    sample code at...
    http://www.19nine78.net/bit-tec/test.htm

    I changed the path from /images/ to /avatars/ so an image would show up on my server but other than that the code should work.

    let me know how you get on.

    cheers

    alastair
     
  11. bushd

    bushd What's a Dremel?

    Joined:
    9 Nov 2002
    Posts:
    241
    Likes Received:
    0
    I figured it out, thanks. </SCRIPT> was missing there.

    Now my next task, making this thing auto detect picture height/width in pixels and adding like 20 to each size.
     
  12. 19nine78

    19nine78 What's a Dremel?

    Joined:
    11 Dec 2002
    Location:
    ayr
    Posts:
    18
    Likes Received:
    0
    I can give you a hint if you want:naughty:
     
  13. bushd

    bushd What's a Dremel?

    Joined:
    9 Nov 2002
    Posts:
    241
    Likes Received:
    0
    Well alright, hint away.
     
  14. 19nine78

    19nine78 What's a Dremel?

    Joined:
    11 Dec 2002
    Location:
    ayr
    Posts:
    18
    Likes Received:
    0
    change this line:
    Code:
    var Imagestring = "<IMG SRC=./images/" + image + ".jpg>"
    to:
    Code:
    var Imagestring = "<IMG name=myImage onload=window.resizeTo(document.myImage.width,document.myImage.height) SRC=avatars/" + image + ".jpg>";
    and adjust the 'src=' to suit your setup.

    cheers

    alastair
     
  15. bushd

    bushd What's a Dremel?

    Joined:
    9 Nov 2002
    Posts:
    241
    Likes Received:
    0
    Thanks, that helped very much.
     

Share This Page