0

I want to create a simple javascript button that will be disabled once the current user clicked it.

I have a zend framework action that I d like to be called once the user clicks it but disabled the button for ever, if the current user already clicked it.

My zend framework action is something like this: `public function addvisitedlocationAction() {

    $locationID = $this->_getParam('location_id');
    echo "Location ID: " . $locationID; 
    $visited = 1;
    $memberID = $this->view->identity;
    $email= $memberID->email;   

    $currentUser = Model_DbTable_Members::getMember($email); 
    $memberID2 = $currentUser['id'];
    echo '<br>Current Member id: ' . $memberID2;
    //$profile = Model_DbTable_Members::findMembersProfile($email);
    $this->view->currentMember = $currentUser; 
    //$this->view->theProfile = $profile; 
    $visitedModel = new Model_DbTable_MembersVisitedLocations();
    $visitedModel->addMemberVisitedLocation($memberID2, $locationID,$visited);

    return $this->_redirect('/restaurant/viewrestaurantlocationprofile/location_id/'. $locationID);
}//end of addvisitedLocation;`

I want to call this once the javascript button is clicked and disable the button for ever for that user.

My problem is I am familiar with javascript but don't really know where to start from. I have a simple image that I can use as a button. My aim is to call that action without redirecting the page and disable the button for the current user.

Any suggestions how I can achieve that?

Thanks.

1
  • You can't do simple things with Zend Framework... Commented Apr 27, 2011 at 12:49

1 Answer 1

2

If you want to call another page without reloading or redirecting the user then you'd need to use AJAX.

Using jQuery, you can do it like this:

function whatever()
{
    $.ajax({
       type: "GET",
       url: "/my/action/to/call",
       data: "mydataitem="+dataitem,
       success: function(html, msg){
           //do something on success
       }
     }); 
}

This will allow you to send data to another Zend Action, which can then process your request.

To disable the button, you can just do $('#myidofbuttonOrimage').attr('disabled', 'disabled');

If you're using a library such as jQuery, this is very simple, otherwise here's some links that may help you.

Hope this helps

Reference: http://api.jquery.com/jQuery.ajax/ Reference: http://www.w3schools.com/ajax/default.asp

Sign up to request clarification or add additional context in comments.

1 Comment

And you can called whatever() using an onclick on the image that you want to be your link. If you're using an image, then you can't add a disabled attribute, you'd need to either remove the link using javascript, or set further clicks to "preventdefault" - see api.jquery.com/event.preventDefault

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.