J
jr
Is "onsubmit" a valid event for an object of type submit? I thought it
was aformevent.
I'm not sure whether you want to submit data from thisformto the php
page that triggers the print operation or not. Clarification of that
might help. If you do, then to use anajaxrequest, you will have to use
javascript to assemble a full post or get request from theformdata
when thebuttonis clicked. It may be better to use a traditionalform
submit and generate a new page with the printer response message on the
server.
If the data is already on the server, you don't need to use aformfor
this, although how does the server know which data to use? Session
cookies? Job id from theform(which you might need to append to the get
request using ?field=value)? In either case, you probably shouldn't be
triggeringajaxrequests from aform'ssubmitbuttonusing an onsubmit
handler.
You could use theform'sonsubmit handler to specify javascript to
execute when the submitbuttonis pressed. Perhaps that's what you want
to do? If you do that, and don't want to execute theform'saction, make
sure your javascript returns false.
Your submitbuttonis probably trying to call it's parentform'saction,
unless your "onsubmit='blah'" is confusing it completely.
Perhaps you should use a normalbutton(rather than a submit) and give
it a value of, for example, "Send to Printer" and, perhaps, use an
appropriate event handler to call the javascript code.
If I had a better understanding of what you were attempting, I might be
able to give better and / or less confusing pointers to possible solutions.
The following javascript and html, if you understand what it shows,
might be useful to you, or it might not. If you don't understand it, but
instead just blindly copy parts, or all, of it, and things still don't
work, well you obviously didn't take the time to try and understand it
first!
<script type="text/javascript">
function clanger() {
// visit the soupdragon
var soupdragon;
if (window.XMLHttpRequest) { // ie7+ etc
soupdragon=new XMLHttpRequest();
}else{ // IE6, IE5
soupdragon=new ActiveXObject("Microsoft.XMLHTTP");
}
soupdragon.onreadystatechange = function()
{
if(soupdragon.readyState == 4)
{
if(soupdragon.status == 200)
document.getElementById('printer_response').innerHTML=
"Received: " + soupdragon.responseText;
else
document.getElementById('printer_response').innerHTML=
"Error code: " + soupdragon.status;
}
}
soupdragon.open(GET, "print_test.php", true);
soupdragon.send();
return false;}
</script>
<formaction="blah" method="whatever" onsubmit="clanger()">
..... fields .....
<input type="submit">
</form>
Rgds
Denis McMahon
Is "onsubmit" a valid event for an object of type submit? I thought it
was aformevent.
Sorry, this is not a form. This is only a button. The event should
be onClick.
I ran the page through the validator and fixed the tables. This
button is not part of the form.
Sorry for not explaining it. The search form pulls barcode labels.I'm not sure whether you want to submit data from thisformto the php
page that triggers the print operation or not. Clarification of that
might help. If you do, then to use anajaxrequest, you will have to use
javascript to assemble a full post or get request from theformdata
when thebuttonis clicked. It may be better to use a traditionalform
submit and generate a new page with the printer response message on the
server.
If the data is already on the server, you don't need to use aformfor
this, although how does the server know which data to use? Session
cookies? Job id from theform(which you might need to append to the get
request using ?field=value)? In either case, you probably shouldn't be
triggeringajaxrequests from aform'ssubmitbuttonusing an onsubmit
handler.
The printer is an FTP printer. There is no live connection. The
script opens
a file and writes the labels to a template. The template gets dropped
on the printer.
The limit is 200 per page. So the button just sends the template to
the printer per page.
You could use theform'sonsubmit handler to specify javascript to
execute when the submitbuttonis pressed. Perhaps that's what you want
to do? If you do that, and don't want to execute theform'saction, make
sure your javascript returns false.
Your submitbuttonis probably trying to call it's parentform'saction,
unless your "onsubmit='blah'" is confusing it completely.
Perhaps you should use a normalbutton(rather than a submit) and give
it a value of, for example, "Send to Printer" and, perhaps, use an
appropriate event handler to call the javascript code.
I think it is a normal button.
I would like to get this AJAX to work first and then the other one.If I had a better understanding of what you were attempting, I might be
able to give better and / or less confusing pointers to possible solutions.
The following javascript and html, if you understand what it shows,
might be useful to you, or it might not. If you don't understand it, but
instead just blindly copy parts, or all, of it, and things still don't
work, well you obviously didn't take the time to try and understand it
first!
It still isn't firing. I ran it through the Validator.
I'm still not getting the javascript to fire.
There is some info about the FTP connection on the print_test.php
page.
The var is $response. I would like $response to be printed between
the div. I just echoed the var $response on the print template page.
----code from print_test.php------
if(!upload) {
echo "FTP upload has failed!";
$response.="FTP upload has failed";
}else{
echo "uploaded <br /> $source_file <br /> to $ftp_server <br /> as
as <br />$destination_file";
}
---------------
Button:
echo "<tr>\n";
echo "<td><input type=\"button\" name=\"print\" value=\"Print current
page\" onClick=\"printFromHere();\"></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<div id='printer_response'>";
echo "</div>";
echo "</table>\n";
It never makes it to the alert.
---------javascxript---------
<script type="text/javascript">
function printFromHere(){
alert(hello);
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').innerHTML="Received:" +
xhr.responseText;
else
document.getElementById('printer_response').innerHTML
="Error code " + xhr.status;
}
}
xhr.open(GET, 'print_test.php', true);
xhr.send(null);
}
Rds,
Janis