Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By AndreyUA on
Hello.
My module renders a page with a picture and a table within. The table holds a list of properties of something. When user clicks on one table cell it fires JS function which loads a picture of it and replaces the existing one on the page. Sounds simple, but how do I put a JQ listener on page element using Drupal way?
for now there is a hook_menu:
<...>$items['shop/%'] = array(
'title' => 'one product',
'title callback' => 'fm_fanshop_load_product_title',
'title arguments' => array(1),
'type' => MENU_NORMAL_ITEM,
'page callback' => 'fm_fanshop_load_product_display',
'page arguments' => array(1),
'access callback' => TRUE,
);
and the page callback:
function fm_fanshop_load_product_display( $arg )
{
...some code which makes an HTML...
return $html;
}
Comments
use-ajax
Firstly, the cells content should be clickable, now you need to use something like below..
Now the clickable URL should be defined in hook_menu() and then content should be returned from this callback in the form json.