Program code:
<script Language=VBScript>
Function print_onclick //Print function
Dim label
label=document.printinfo.label.value //Get the data of the HTML page
set objfs=CreateObject("Scripting.FileSystemObject") //Create an instance of the FileSystem component object
set objprinter=objfs.CreateTextFile ("LPT1:",true) //Establish a connection with the printer
objprinter.Writeline("____________________________") //Output the printed content
objprinter.Writeline("| |")
objprinter.Writeline("| The data you print is: "&label& " |")
objprinter.Writeline("| |")
objprinter.Writeline("|_______________________________|")
objprinter.close //Disconnect from the printer
Set objprinter = nothing
Set objfs = nothing // Close the FileSystem component object
End Function
</script>
Server-side script:
<%
Set conn=server.CreateObject ("adodb.connection")
conn.Open "DSN=name;UID=XXXX;PWD=XXXX;"
Set Rs = server.CreateObject("adodb.recordset")
Rs.Open("select..."),conn,1,1
HTML page encoding
for interacting with the database
:
<HTML>
………
<FORM ID=printinfo NAME="printinfo" >
<INPUT type="button" value="Print>>" id=print name=print > //Call the print function
<INPUT type="hidden" id="text1" name="label" value=<%=…………%>> //Save the data sent from the server
………
</HTML>