I have a search box form, when it is submitted, the results are posted the page displays labels. I need to print these labels displayed on the page by another form with a button at the bottom of the page.
The search form works. I need to add this HTML button input to call the javascript function,
printFromHere(). I'm not clear on what needs to happen in the 2nd form action?
Do I need the button to POST? I need to get results back from the XMLHTTP request. So do I put action='$me' so the page will call itself again?
Also where do I put the submit function so the button gets submitted? Is the name='submit' going to submit the button when it is clicked? Do I need onClick?
When the button is submitted I need the onsubmit='printFromHere()' to call javascript. So I think that is enough to call my print page. I'll enclose the javascript function.
echo "<form id='print' onsubmit='printFromHere();'>";
echo "<table>";
echo "<tr>";
echo "<td colspan='13' align='center'><input type='button' name='submit' value='Print labels on this page'></td>\n";
echo "</tr>";
echo "<tr>";
echo "<td><div id='printer_response'>";
echo "</div>";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</form>";
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').innerHTML="Received:" + xhr.responseText;
else
document.getElementById('printer_response').innerHTML ="Error code " + xhr.status;
}
}
xhr.open(GET, "print_test.php", true);
xhr.send(null);
}
</script>
thanks, I don't think the button is firing.