I need to call the gh_cart_prove when the BUTTON is clicked.

function gh_view_categories(){
  $a.='<td><strong>'.'Soglia minima:'.'</strong></td>';
  $a.='<td><strong>'.'Tot attuale:'.'</strong></td>';
  $a.='<td><strong>'.'Crea ordine'.'</strong></td>';
  $query = db_select('uc_product_classes', 'u')
    ->fields('u', array('name','soglia', 'totattuale'));
  $result = $query->execute();
  while ($record = $result->fetchAssoc()) {
    $a.='<td>'.'<button onClick="gh_cart_prove($idUser)">BUTTON</button>'.'</td>';



  return ($a);

The button appear but it not works. the function is correctly declared. How can I resolve this problem?

  • 1
    Welcome to Drupal Answers! Is gh_cart_prove() a JavaScript function?
    – apaderno
    Sep 28, 2015 at 16:04
  • no it isn't.... Sep 28, 2015 at 16:09
  • 1
    if gh_cart_prove is NOT a JS, it may help to get an answer if you EDIT your question to explain what it IS ... Sep 28, 2015 at 17:18
  • I would assume that you have gh_cart_prove() as a PHP function in a contributed module? What I don't see here is a <form> element. If you want to handle it like a form, I would recommend placing one in your table (even if it's within your existing <td>). Otherwise, Javascript would be your best approach. Sep 28, 2015 at 21:53

1 Answer 1


Assign an id to the button and use Jquery, set the $idUser in a data attribute example :

 <button id="buddon-id" data-user="<?php echo $idUser;?>" >button</button>
    $("#button-id").on("click", function(e){
       userid = $(this).attr("data-user");
  • Hi Riccardo, thanks a lot.. I'm new with jquery, Where do I put the code of the script? in what way? Sep 29, 2015 at 7:34
  • I suggest you to create a js file and insert the path in the yourthemename.info file, install jquery update module and add the code after $ = JQuery; jQuery(document).ready(function() { $ = jQuery; //.... your code here }); Sep 29, 2015 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.