From: jr on 1 Aug 2010 11:13 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, I changed it to print labels on this page.
From: Denis McMahon on 1 Aug 2010 11:53 On 01/08/10 16:12, jr wrote: >>> </div> >>> <div id='printer_response'> >>> </div> >>> document.getElementById.printer_response="Received:" + >>> xhr.responseText; >>> else >>> document.getElementById.printer_response ="Error code >>> " + xhr.status; >> 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. > 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
First
|
Prev
|
Pages: 1 2 Prev: FREE SOFTWARE Next: AJAX function doesn't fire from button input form |