Alpha Video Training
Results 1 to 7 of 7

Thread: Need to press the button twice

  1. #1
    Member
    Real Name
    Michael Cornford
    Join Date
    Oct 2011
    Location
    East Sussex, UK
    Posts
    884

    Default Need to press the button twice

    This code works in an Html page and an a5w page as expected.


    jQuery('button').click(function()
    {
    var url='data:application/vnd.ms-excel,' + encodeURIComponent(jQuery('#tableWrap').html())
    location.href=url
    return false
    })

    However in a dialog component it requires 2 clicks to work.

    Anyone got any idea why this is so?


    Michael

  2. #2
    "Certified" Alphaholic TheSmitchell's Avatar
    Real Name
    Sarah
    Join Date
    Apr 2012
    Posts
    1,315

    Default Re: Need to press the button twice

    I don't follow. What is the problem?
    Alpha Anywhere latest pre-release

  3. #3
    Member
    Real Name
    Michael Cornford
    Join Date
    Oct 2011
    Location
    East Sussex, UK
    Posts
    884

    Default Re: Need to press the button twice

    The program works, but after the second click on an on click event.

    The first click does nothing.
    ---------------------------------------------------------------------------------------
    HTML page in <Head>
    <script type="text/javascript">
    $(function(){
    $('button').click(function(){
    var url='data:application/vnd.ms-excel,' + encodeURIComponent($('#tableWrap').html())
    location.href=url
    return false
    })
    })
    </script>

    <body>
    <button>click me</button>
    <div id="tableWrap">
    <table>
    <thead>
    <tr><th>Qty</th><th>Qty Available</th><th>Grower</th></tr>
    </thead>
    <tbody>
    <tr><td>1</td><td>2</td><td>Frog</td></tr>
    <tr><td>21</td><td>22</td><td>Cat</td></tr>
    <tr><td>31</td><td>32</td><td>Dog</td></tr>
    <tr><td>41</td><td>42</td><td>Fish</td></tr>
    </tbody>
    </table>
    </div>
    </body>

    This works on the first click.
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Dialog

    function mark(){

    var qty = {dialog.Object}.listGetValue('ListDemo','Bottle');
    var name = {dialog.Object}.listGetValue('ListDemo','WineName');
    var year = {dialog.Object}.listGetValue('ListDemo','Year');

    var save = localStorage.getItem('lsrow');

    if(save == undefined ){

    //Build the header

    var txt = "<table><thead><tr><th>Qty</th><th>Wine</th><th>Year</th></tr></thead><tbody>"


    }
    else


    var txt = localStorage.getItem('lsrow');

    alert(txt);
    var row = "<tr><td>" + qty + "</td><td>" + name + "</td><td>" + year + "</td></tr>"
    txt = txt + row
    // End
    localStorage.setItem('lsrow',txt);

    {dialog.object}.runAction('table');




    }

    This function builds the table in a new panel. Mark() is called from the on click event of a list row.

    Then I have a button on the new panel

    jQuery('button').click(function()
    {
    var url='data:application/vnd.ms-excel,' + encodeURIComponent(jQuery('#tableWrap').html())
    location.href=url
    return false
    })

    Works in the correct way on second and subsequent click.

    --------------------------------------------------------------------------------------------------------------------------------

  4. #4
    "Certified" Alphaholic TheSmitchell's Avatar
    Real Name
    Sarah
    Join Date
    Apr 2012
    Posts
    1,315

    Default Re: Need to press the button twice

    Did you define your jQuery('button').click(...) in one of the events for the new button? Or is it defined in the JavaScript code section for the UX?
    Alpha Anywhere latest pre-release

  5. #5
    Member
    Real Name
    Michael Cornford
    Join Date
    Oct 2011
    Location
    East Sussex, UK
    Posts
    884

    Default Re: Need to press the button twice

    Sorry I have had to move on. It was on the button's onclick event.

    Michael

    PS if I manage a solution that works I will share it. (I have a good solution for Chrome Firefox but it does not work in IE)

  6. #6
    "Certified" Alphaholic TheSmitchell's Avatar
    Real Name
    Sarah
    Join Date
    Apr 2012
    Posts
    1,315

    Default Re: Need to press the button twice

    Quote Originally Posted by Michael1954 View Post
    Sorry I have had to move on. It was on the button's onclick event.

    Michael

    PS if I manage a solution that works I will share it. (I have a good solution for Chrome Firefox but it does not work in IE)
    Hi Michael,

    If your jQuery code is defined in the button's click event---the click event for the button that is supposed to perform this action ---then it makes sense that it doesn't work the first time. The first time you click the button, the jQuery code you have there executes and a function is registered for the 'click' event for all 'button' elements. The second time you click the button, the function you bound to your button's click event is executed *and* your jQuery code executes again - possible registering your function on the click event twice, which potentially means it's called twice the third time you click the button (if clicking the button a third time is possible.)

    The way I see it, you have 2 options:

    Option 1: Move the entire block of code to the client-side "onInitializeComplete". You want to register the event handler once - ideally immediately after the button has been rendered/added to the DOM. If the button is dynamically added later (ie, not during the first load of the UX), then you need to look to another location to put your jQuery code so that you can execute it after the HTML is added to the DOM.

    Option 2: If you're already putting this code inside the button's click event, then instead of registering the event handler, you could just execute the code directly:
    Code:
    var url='data:application/vnd.ms-excel,' + encodeURIComponent(jQuery('#tableWrap').html());
    location.href=url;
    return false;
    Good luck
    ---
    Sarah
    Alpha Anywhere latest pre-release

  7. #7
    Member
    Real Name
    Michael Cornford
    Join Date
    Oct 2011
    Location
    East Sussex, UK
    Posts
    884

    Default Re: Need to press the button twice

    Thanks will try

Similar Threads

  1. Code to press a button using keyboard instead of the mouse?
    By doorscomputers in forum Application Server Version 11 - Web/Browser Applications
    Replies: 0
    Last Post: 07-29-2012, 01:55 AM
  2. Modify session variable on button press
    By GGAllen in forum Application Server Version 10 - Web/Browser Applications
    Replies: 0
    Last Post: 12-15-2011, 10:03 AM
  3. Populate a field when tab button is press
    By eboughey1 in forum Application Server Version 10 - Web/Browser Applications
    Replies: 1
    Last Post: 05-21-2010, 10:45 PM
  4. Populating fields in a form based on button press
    By tcentral in forum Alpha Five Version 8
    Replies: 5
    Last Post: 01-01-2008, 10:03 AM
  5. Button properties - dashed lines on press
    By dik_coleman in forum Alpha Five Version 8
    Replies: 11
    Last Post: 07-20-2007, 11:52 AM

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
  •