SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Attaching event with window.open()

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

    $(document).ready(function()
    {

    function invoice()
    {
    var wind = window.open('','_blank','width=700,height=700,scrollbars=yes,status=yes');

    var html = '<input type="button" id="submit_button" onclick="print_invoice();" value="Submit"/>';
    $(wind.document.body).html(html);
    }

    $('#print_invoice').click(invoice);

    });

    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?

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by afoysal View Post
    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.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @paul I would like to add a function to window.open()

    Thanks for reply

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by afoysal View Post
    @paul I would like to add a function to window.open()

    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.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by afoysal View Post
    I would like to attach a function in the input button id="submit_button" to save the invoice in database.
    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.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    SitePoint Zealot
    Join Date
    Nov 2008
    Location
    UK
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by treacle0996 View Post
    I would use a jquery .ajax call
    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.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  8. #8
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by felgall View Post
    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 code examples that you can view, download, and experiment with too.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  9. #9
    SitePoint Zealot
    Join Date
    Nov 2008
    Location
    UK
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    There's no need to include the entire huge jQuery library just to do one ajax call.
    Good point. I've been staring at so much jquery lately - I can't think of javascript without it!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •