View Full Version : Check a button has been pressed

04-24-2008, 08:02 AM
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.

04-24-2008, 08:36 AM
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.

Philip M
04-24-2008, 08:50 AM
<script type="text/javascript">

function link_enable(link) {
if (typeof link.disabled != 'undefined') link.disabled = false;
link.onclick = null;


<input type = "button" name = "AjaxCall" value = "Make Call to Ajax" onclick="link_enable(document.links[0])">
<a href="http://www.codingforums.com" onclick="return false" disabled="disabled">LINK</a>

It is your responsibility to die() if necessary….. - PHP Manual

Bill Posters
04-25-2008, 08:51 AM
<a … disabled="disabled">LINK</a>
In practise, wouldn't a class or rel be conceptually and technically more valid option?
Just a thought.

Philip M
04-25-2008, 08:15 PM
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.

Bill Posters
04-26-2008, 06:35 PM
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 (http://www.w3.org/QA/Tips/goodclassnames) 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.

Philip M
04-27-2008, 09:09 AM
Another possibility is to replace the link with a button using its disabled attribute.