how to send XMLHTTP object from a button input

J

jr

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,
 
J

Jeff North

On Sat, 31 Jul 2010 18:31:38 -0700 (PDT), in comp.lang.javascript jr
<[email protected]>
| 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;
 
J

jr

@yahoo.com>
| 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.
 
D

Denis McMahon

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
 
J

jr

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);
}

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
 
J

jr

@yahoo.com>
| 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, I changed it to print labels on this page.
 
D

Denis McMahon

Okay, thanks, can I do it like this?
document.getElementById('printer_response').innerHTML="Received:" +
xhr.responseText;

If innerHTML is a valid property for a div, and the result of
'"Received:" + xhr.responseText' when placed inside the div doesn't
break anything, it may indeed do as you want. However, it also may not,
for example if "xhr.responseText" included "</body>" and / or "</html>",
it could break things significantly under certain DTDs.

Inside a div I would expect text to be encapsulated in a block element
such as a header or paragraph element.

Rgds

Denis McMahon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top