Attaching event with

I am developing a billing system using codeigniter - mysql. I would like to print invoice using of JavaScript . My code is like below


function invoice()
var wind =‘’,‘_blank’,‘width=700,height=700,scrollbars=yes,status=yes’);

var html = ‘<input type=“button” id=“submit_button” onclick=“print_invoice();” value=“Submit”/>’;



I would like to attach a function in the input button id=“submit_button” to save the invoice in database.

Could any one say how can I do that?

Instruct the user to go to the File menu and choose Save, or to press Ctrl+S to save the page.

@paul I would like to add a function to

Thanks for reply

Oh hang on, not save it to a file, but to save the transaction to the database. Sorry, but someone else would have to help you with that.

You should post that question in the appropriate forum for whichever server side language you are using to access the database. Even if you are going to use JavaScript to send the request to the server without reloading the page you’ll need to get the version without JavaScript working first and most of the processing will be done by the server script even after you add the JavaScript.

I would use a jquery .ajax call to a php file (or whatever language you are using), and that file should handle writing to the database.

something like : $.ajax({url:‘writeinvoice.php?value=’+value+‘&item=’+itemname }

writeinvoice.php has to expect whatever parameters you send from javascript, and include them into an ‘insert invoice into database’ function.

There’s no need to include the entire huge jQuery library just to do one ajax call. Unless you already have jQuery attached to the page you can manage the same call in about a dozen lines of ordinary JavaScript.

Examples of which can be found in this Bulletproof Ajax book, which has live online [url=“”]code examples that you can view, download, and experiment with too.

Good point. I’ve been staring at so much jquery lately - I can’t think of javascript without it!