Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Mar 2008
    Posts
    88
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Check a button has been pressed

    I need to be sure an ajax function has been called before a link is clicked.
    Ajax call was made by clicking a button. the link needs to be appended a y or n depending on whether the button was pressed.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    At the end of execution of ajax function, set some value to a hidden field, then you could check the value when you click on the link.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    beedie (04-24-2008)

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,243
    Thanks
    203
    Thanked 2,555 Times in 2,533 Posts
    Code:
    <script type="text/javascript"> 
    
    function link_enable(link) {
    if (typeof link.disabled != 'undefined') link.disabled = false;
    link.onclick = null;
    }
    
    </script> 
    
    <form>
    <input type = "button" name = "AjaxCall" value = "Make Call to Ajax"  onclick="link_enable(document.links[0])">
    <br><br>
    <a href="http://www.codingforums.com" onclick="return false" disabled="disabled">LINK</a>
    </form>
    It is your responsibility to die() if necessary….. - PHP Manual

  • Users who have thanked Philip M for this post:

    beedie (04-24-2008)

  • #4
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by Philip M View Post
    Code:
    <a … disabled="disabled">LINK</a>
    In practise, wouldn't a class or rel be conceptually and technically more valid option?
    Just a thought.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,243
    Thanks
    203
    Thanked 2,555 Times in 2,533 Posts
    Quote Originally Posted by Bill Posters View Post
    In practise, wouldn't a class or rel be conceptually and technically more valid option?
    Just a thought.
    No idea. There may possibly be something in what you say. For myself, my attitude is that if it works then it meets my needs. If you have a better or more technically elegant solution then I am sure that beedie would be interested to see it.

  • #6
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    I might use a similar approach, but would base it around the class attribute instead of the custom, invalid disabled attribute (invalid when used with anchor elements).
    I appreciate that disabled="disabled" has a better semantic ring to it in terms of attribute names, but I personally wouldn't consider it a good solution precisely because it needlessly adds invalidating markup to the document.

    class is a valid alternative and can be used with semantics in mind to an extent that would be at least as meaningful to a browser as disabled="disabled" on an anchor.


    As an alternative, if the clicking of the link is dependent upon the triggering of an AJAX function, I might consider building the AJAX functionality into the link.

    i.e. When the link is clicked, it runs the AJAX function, then performs its other function(s) once the AJAX response comes back.


    - or -

    I might consider whether the link even needs to be on-screen before the AJAX function has been called.

    i.e. The AJAX function adds the link to the page once the response comes back.


    Which option I'd consider best would depend on the purpose of the AJAX function and the link.

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,243
    Thanks
    203
    Thanked 2,555 Times in 2,533 Posts
    Another possibility is to replace the link with a button using its disabled attribute.


  •  

    Posting Permissions

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