From: jr on
All I want to do is to fire a javascript when the user clicks the
'print the current page' button.
It doesn't fire. I don't know if I need another event besides
onClick? This is what I have in the form but it doesn't work.
I would really like it if the xmlhttp response text came back in the
printer response div.
<div id="printbutton">
<input type="button" name="print" value="Print this page"
id="printbutton" "printFromHere()";>
</div>
<div id='printer_response'>
</div>

function printFromHere(){

var xhr = document.forms[0].search_zonenm.value;
if ( window.XMLHttpRequest ) {// code for IE7+,
Firefox, Chrome, Opera, Safari
xhr=new XMLHttpRequest();
}else{ // code for IE6, IE5
xhr=new ActiveXObject("Microsoft.XMLHTTP");
}
xhr.onreadystatechange = function()
{
if(xhr.readyState == 4)
{
if(xhr.status == 200)

document.getElementById.printer_response="Received:" +
xhr.responseText;
else
document.getElementById.printer_response ="Error code
" + xhr.status;
}
};
xhr.open(GET, "print_test.php", true);
xhr.send(null);
}

thanks,
From: Jeff North on
On Sat, 31 Jul 2010 18:31:38 -0700 (PDT), in comp.lang.javascript jr
<jlrough(a)yahoo.com>
<b59d4b9c-6def-4a10-bd01-72f3ec50f87b(a)i19g2000pro.googlegroups.com>
wrote:

>| All I want to do is to fire a javascript when the user clicks the
>| 'print the current page' button.
>| It doesn't fire. I don't know if I need another event besides
>| onClick? This is what I have in the form but it doesn't work.
>| I would really like it if the xmlhttp response text came back in the
>| printer response div.
>| <div id="printbutton">
>| <input type="button" name="print" value="Print this page"
>| id="printbutton" "printFromHere()";>

id="printbutton" onclick="printFromHere();">

I'd recommend that you use a different term as Print this page isn't
actually going to print the page, is it?

>| </div>
>| <div id='printer_response'>
>| </div>
>|
>| function printFromHere(){
>|
>| var xhr = document.forms[0].search_zonenm.value;

var xhr; // = document.forms[0].search_zonenm.value;

>| if ( window.XMLHttpRequest ) {// code for IE7+,
>| Firefox, Chrome, Opera, Safari
>| xhr=new XMLHttpRequest();
>| }else{ // code for IE6, IE5
>| xhr=new ActiveXObject("Microsoft.XMLHTTP");
>| }
>| xhr.onreadystatechange = function()
>| {
>| if(xhr.readyState == 4)
>| {
>| if(xhr.status == 200)
>|
>| document.getElementById.printer_response="Received:" +
>| xhr.responseText;
>| else
>| document.getElementById.printer_response ="Error code
>| " + xhr.status;
>| }
>| };
>| xhr.open(GET, "print_test.php", true);
>| xhr.send(null);
>| }
>|
>| thanks,
From: jr on
On Jul 31, 8:04 pm, Jeff North <jnort...(a)yahoo.com.au> wrote:
> On Sat, 31 Jul 2010 18:31:38 -0700 (PDT), in comp.lang.javascript jr
> <jlro...(a)yahoo.com>
> <b59d4b9c-6def-4a10-bd01-72f3ec50f...(a)i19g2000pro.googlegroups.com>
> wrote:
>
> >| All I want to do is to fire a javascript  when the user clicks the
> >| 'print the current page' button.
> >| It doesn't fire.  I don't know if I need another event besides
> >| onClick?  This is what I have in the form  but it doesn't work.
> >| I would really like it if the xmlhttp response text came back in the
> >| printer response div.
> >| <div id="printbutton">
> >| <input type="button" name="print" value="Print this page"
> >| id="printbutton" "printFromHere()";>
>
> id="printbutton" onclick="printFromHere();">
>
> I'd recommend that you use a different term as Print this page isn't
> actually going to print the page, is it?
>
> >| </div>
> >| <div id='printer_response'>
> >| </div>
> >|
> >| function printFromHere(){
> >|
> >| var xhr = document.forms[0].search_zonenm.value;
>
> var xhr; // = document.forms[0].search_zonenm.value;
>
>
>
> >|                 if ( window.XMLHttpRequest ) {// code for IE7+,
> >| Firefox, Chrome, Opera, Safari
> >|             xhr=new XMLHttpRequest();
> >|           }else{ // code for IE6, IE5
> >|             xhr=new ActiveXObject("Microsoft.XMLHTTP");
> >|           }
> >|     xhr.onreadystatechange  = function()
> >|     {
> >|          if(xhr.readyState  == 4)
> >|          {
> >|               if(xhr.status  == 200)
> >|  
> >| document.getElementById.printer_response="Received:"  +
> >| xhr.responseText;
> >|               else
> >|                  document.getElementById.printer_response ="Error code
> >| " + xhr.status;
> >|          }
> >|     };
> >|    xhr.open(GET, "print_test.php",  true);
> >|    xhr.send(null);
> >| }
> >|
> >| thanks,

okay,l I tried to rewrite this question and I was going to repost it
so I could include the view source so it makes more sense
but I noticed a lot of problems with the view source.
From: Denis McMahon on
On 01/08/10 02:31, jr wrote:
> All I want to do is to fire a javascript when the user clicks the
> 'print the current page' button.
> It doesn't fire. I don't know if I need another event besides
> onClick? This is what I have in the form but it doesn't work.
> I would really like it if the xmlhttp response text came back in the
> printer response div.
> <div id="printbutton">
> <input type="button" name="print" value="Print this page"
> id="printbutton" "printFromHere()";>
> </div>
> <div id='printer_response'>
> </div>
>
> function printFromHere(){
>
> var xhr = document.forms[0].search_zonenm.value;
> if ( window.XMLHttpRequest ) {// code for IE7+,
> Firefox, Chrome, Opera, Safari
> xhr=new XMLHttpRequest();
> }else{ // code for IE6, IE5
> xhr=new ActiveXObject("Microsoft.XMLHTTP");
> }
> xhr.onreadystatechange = function()
> {
> if(xhr.readyState == 4)
> {
> if(xhr.status == 200)
>
> document.getElementById.printer_response="Received:" +
> xhr.responseText;
> else
> document.getElementById.printer_response ="Error code
> " + xhr.status;
> }
> };
> xhr.open(GET, "print_test.php", true);
> xhr.send(null);
> }
>
> thanks,

1) You should try to use the getElementById method of the document
object properly. Read the manual for the getElementById method of the
document object.

2) You probably want to set a property of the 'printer_response' div to
the text you want to display, rather than the div itself. Read the
manual for the properties of the div object, as well as global
properties, to identify the one you should use.

Rgds

Denis McMahon
From: jr on
On Aug 1, 2:05 am, Denis McMahon <denis.m.f.mcma...(a)googlemail.com>
wrote:
> On 01/08/10 02:31, jr wrote:
>
>
>
>
>
> > All I want to do is to fire a javascript  when the user clicks the
> > 'print the current page' button.
> > It doesn't fire.  I don't know if I need another event besides
> > onClick?  This is what I have in the form  but it doesn't work.
> > I would really like it if the xmlhttp response text came back in the
> > printer response div.
> > <div id="printbutton">
> > <input type="button" name="print" value="Print this page"
> > id="printbutton" "printFromHere()";>
> > </div>
> > <div id='printer_response'>
> > </div>
>
> > function printFromHere(){
>
> > var xhr = document.forms[0].search_zonenm.value;
> >                 if ( window.XMLHttpRequest ) {// code for IE7+,
> > Firefox, Chrome, Opera, Safari
> >              xhr=new XMLHttpRequest();
> >            }else{ // code for IE6, IE5
> >              xhr=new ActiveXObject("Microsoft.XMLHTTP");
> >            }
> >     xhr.onreadystatechange  = function()
> >     {
> >          if(xhr.readyState  == 4)
> >          {
> >               if(xhr.status  == 200)
>
> > document.getElementById.printer_response="Received:"  +
> > xhr.responseText;
> >               else
> >                  document.getElementById.printer_response ="Error code
> > " + xhr.status;
> >          }
> >     };
> >    xhr.open(GET, "print_test.php",  true);
> >    xhr.send(null);
> > }
>
> > thanks,
>
> 1) You should try to use the getElementById method of the document
> object properly. Read the manual for the getElementById method of the
> document object.
>
> 2) You probably want to set a property of the 'printer_response' div to
> the text you want to display, rather than the div itself. Read the
> manual for the properties of the div object, as well as global
> properties, to identify the one you should use.
>
> Rgds
>
> Denis McMahon

Okay, thanks, can I do it like this?


document.getElementById('printer_response').innerHTML="Received:" +
xhr.responseText;
Rgds,
Janis