Javascript help, please?

Do you have a technical question that doesn't really fit a specific console? Want some general info on electronics, hacking, making cookies, etc? Here's the place to ask! Go nuts.

Moderator: Moderators

Post Reply
Electric Rain
Senior Member
Posts: 1911
Joined: Tue Mar 29, 2005 12:39 pm
PSN Username: Denki_no_Ame
Location: What's it to you? Stalker...

Javascript help, please?

Post by Electric Rain »

This is the second time I've had to ask for Javascript help from you guys... it's kind of embarrassing... I'm supposed to be a webmaster and all... >.>

Maybe I'm just tired or something... but I can't figure this out. I'm using this guide to create a printing pop-up. The guide shows you how to do it for images, and then, at the bottom of the page, explains what needs to be done if you want to print a div tag instead. Well... I can't get that to work... I don't quite understand what it's telling me to do. Can someone creating a sample for me using the alternate method detailed at the bottom of the page? Thanks... :oops:

Edit: Great... I finally got to my 900th post, and it makes me look like an idiot. :lol:
Image
gannon
Moderator
Posts: 6974
Joined: Sun Apr 04, 2004 4:48 pm
Location: Near that one big lake
Contact:

Post by gannon »

The lines

Code: Select all

return "<html>\n" +
    "<head>\n" +
    "<title>Temporary Printing Window</title>\n" +
    "<script>\n" +
    "function step1() {\n" +
    "  setTimeout('step2()', 10);\n" +
    "}\n" +
    "function step2() {\n" +
    "  window.print();\n" +
    "  window.close();\n" +
    "}\n" +
    "</scr" + "ipt>\n" +
    "</head>\n" +
    "<body onLoad='step1()'>\n" +
    "<img src='" + src + "'/>\n" +
    "</body>\n" +
    "</html>\n";
are just the html code itself, just replace the line

Code: Select all

    "<img src='" + src + "'/>\n" +
with things like

Code: Select all

    "<div>Test div 1</div><div>Test div 2!</div>\n" +
Electric Rain
Senior Member
Posts: 1911
Joined: Tue Mar 29, 2005 12:39 pm
PSN Username: Denki_no_Ame
Location: What's it to you? Stalker...

Post by Electric Rain »

Right, I know that, but... huh, wow, I actually didn't really ask the question I meant to ask. :shock:

My div is very large... there's lots of stuff inside them, and there are multiple (10) divs on a single page. You see how, with the presence of

Code: Select all

onClick="printme(event)"
inside the image tag, you can use this code over and over for multiple images? The code actually takes the src value of the image tag and uses it for the src of the image on the temp pop-up page. I need it to do this for a div instead. I need to be able to click on a push button, actually, and have it open the div specified by the push button... if you know what I mean... ah, I can't concentrate right now! :?
Image
gannon
Moderator
Posts: 6974
Joined: Sun Apr 04, 2004 4:48 pm
Location: Near that one big lake
Contact:

Post by gannon »

Ah, so you want to be able to click on 1 of multiple divs and have it print that div?
I really don't see why they used events here since they could've just used

Code: Select all

printme(this.src)
I'd think for getting the contents of the current div you could use something like

Code: Select all

printme(this.innerHTML)
Electric Rain
Senior Member
Posts: 1911
Joined: Tue Mar 29, 2005 12:39 pm
PSN Username: Denki_no_Ame
Location: What's it to you? Stalker...

Post by Electric Rain »

I see. Alright, thanks man! I'll try that... later... when it's not 3:00AM. :P
Image
Post Reply