SitePoint Sponsor |
|
User Tag List
Results 1 to 9 of 9
-
May 26, 2001, 04:56 #1
- Join Date
- May 2001
- Location
- Australia
- Posts
- 54
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
referencing form element - please help!!
My question refers to a javascript I'm working on.
I have a form which displays its output in a textarea on the same page. This part is working well, but what I'm trying to do (without success!) is create a button which, when clicked, will open a new window which contains (only) the contents of that textarea. I should also add that the original form is in a frame.
Is it possible to do this?! I've been looking for information on the web (even in official documentation) but nothing I've tried has worked. I'd appreciate any & all help!Visit http://astroguitar.cjb.net!
-
May 26, 2001, 08:57 #2
- Join Date
- Mar 2001
- Location
- Mexico
- Posts
- 1,287
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi,
This function will open a new window when you press the submit or any other button
Code:function o(text) { var w = window.open("",""); w.document.write("<html><body><h1>"+text+"</h1></body></html>"); }
To call this function when submit button is clicked write
Code:<script language=javascript> function myfunction() { ... o(output_of_the_form); } </script> <form onsubmit="myfunction()" ...
Code:<script language=javascript> function myfunction() { ... o(output_of_the_form); } </script> <form ..> <input type=button onclick="myfunction()" ...
-
May 27, 2001, 00:54 #3
- Join Date
- May 2001
- Location
- Australia
- Posts
- 54
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
printing new window
Thank you so much!! That works beautifully.
My javascript knowledge is pretty poor, so I really appreciate your help!
But now I have another problem. When I try to print that newly created window (just using the browser's print option) it prints the original window (not the new one). Very frustrating! It does this with Opera, IE and Netscape, so I'm guessing it's not a browser problem.
Is there a Javascript-related reason it won't print the new window? Is there anything I can do??Last edited by slp; May 27, 2001 at 01:02.
-
May 28, 2001, 17:15 #4
- Join Date
- Mar 2001
- Location
- Mexico
- Posts
- 1,287
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
could you include your code?
I tested with IE 5.5 & NN 4.7 (Win) and I printed the frame's contents without problems
Paul
-
May 29, 2001, 02:55 #5
- Join Date
- May 2001
- Location
- Australia
- Posts
- 54
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I suppose the relevant parts of the code would be the functions in the head section:
Code:function o(text) { var w = window.open("",""); w.document.write("<html><body><PRE>"+text+"</PRE></body></html>"); } function Print() { o(document.cgen.display.value); }
And the button in the body:
Code:<INPUT type="button" name ="print" value="print" onClick="Print(this.form)">
And, like I said, the wrong window gets printed (using Netscape 4.04 and IE 5.0. Opera 5.01 crashes!)
-
May 29, 2001, 13:03 #6
- Join Date
- Mar 2001
- Location
- Mexico
- Posts
- 1,287
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Re: printing new window
Originally posted by slp
When I try to print that newly created window (just using the browser's print option) it prints the original window (not the new one)
Code:function o(text) { var w = window.open("",""); if (window.print) pcommand = '<a href="javascript:parent.frames[1].print()">Click here to print this window</a><br>'; w.document.write("<html><body>"+pcommand+"<PRE>"+text+"</PRE></body></html>"); }
Paul
-
May 29, 2001, 13:06 #7
- Join Date
- Mar 2001
- Location
- Mexico
- Posts
- 1,287
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Note that
parent.frames[i].print()
where the first frame is i=0, second is i=1, etc
-
May 30, 2001, 06:21 #8
- Join Date
- May 2001
- Location
- Australia
- Posts
- 54
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
printing problem solved
Thanks for your suggestions, but when I tried it out the same thing happened - it printed out the original window.
I was just about to give in to despair, when by an unbelievable stroke of luck, I came across someone who had the exact same problem only 2 days ago! Looks like this person finally managed to figure out the printing problem: the new window has to be closed when it's finished!
The message can be found here: http://freewarejava.com/ubb/Forum1/HTML/016136.html
So I've incorporated that into the code you gave me about referencing the output of the form & it all works! (Although the print() function doesn't work in some browsers, the new window is properly displayed in all, and can be successfully printed manually. So I'm happy)
Thanks very much for all your help. I really appreciate the time you've taken, and I've learned a few things about Javascript which I'm sure will come in handy in the future!Visit http://astroguitar.cjb.net!
-
May 30, 2001, 12:50 #9
- Join Date
- Mar 2001
- Location
- Mexico
- Posts
- 1,287
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Re: printing problem solved
Originally posted by slp
Thanks very much for all your help. I really appreciate the time you've taken, and I've learned a few things about Javascript which I'm sure will come in handy in the future!
I'm glad that you have solved your problem.
Paul
Bookmarks