1

I'm trying when i submit a value to jqgrid box on multiple selected rows to Update the data of specific columns.My code is this but when i click OK in jqgrid nothing happens and function is not called :

 jQuery(document).ready(function(){
 jQuery('#list1').jqGrid('navButtonAdd', '#list1_pager', 
    {
        'caption'      :  'Resubmit', 
        'buttonicon'   : 'ui-icon-pencil', 
        'onClickButton': function()
    {
    var str = prompt("Please enter data of Column")
        var selr = jQuery('#list1').jqGrid('getGridParam','selarrrow');
            $(selector).load('Updatestatus.php', {'string': str,'box[]'  : selr })
        },
        'position': 'last'
    });

});

The function that updates the column of the table:

 function update_data($data)
    {
// If bulk operation is requested, (default otherwise)
 if ($data["params"]["bulk"] == "set-status")
      { 
      $selected_ids = $data["cont_id"]; 
      $str = $data["params"]["data"];
            mysql_query("UPDATE out_$cmpname SET cont_status = '$str' WHERE cont_id IN ($selected_ids)");

      die;
   } 

    }

I'm new to jqgrid and Jquery.What can i do to call and execute this function when i click ok? Thanks in advance!

gakis
  • 25
  • 5

1 Answers1

0

You'll need a Ajax-call for this. I see you're using jQuery, have a look at http://api.jquery.com/load/

With this function, you can load PHP or HTML with jQuery to a certain element.

Pieter
  • 1,823
  • 1
  • 12
  • 16
  • The php function is in the same file with Jquery.how can i call it from jquery?Sorry for dumb questions but i'm new. – gakis Jul 18 '13 at 09:03
  • You should place the function in a separate file with PHP extension. Echo the result in that file, load it into your main document with the `load`-function of jQuery. – Pieter Jul 18 '13 at 09:35
  • In php file i must connect mysql database?how can i pass the submit text and selected checkboxes to php file? – gakis Jul 18 '13 at 10:14
  • Yes, you should. See the php file as a 'machine' that echo's output, that output will be loaded into a div/table. You can pass variables with `load()`, see documentation. – Pieter Jul 18 '13 at 10:18
  • Advise: make a PHP-file with `echo('test')` and add `$('div.test').load('url_to_php.php')`. Test and try further with transferring variables etc. If you understand how it works, try it with your more complicated code. – Pieter Jul 18 '13 at 10:20
  • Helpful sources: http://stackoverflow.com/questions/12524228/how-to-load-php-file-into-div-by-jquery and http://stackoverflow.com/questions/8674877/using-jquery-load-to-pass-a-parameter-to-and-call-a-php-function – Pieter Jul 18 '13 at 10:22
  • Thank you Pieter!I understand how it works,it appeared the echo of php in the div.But i can not pass my variable str to php.what is the right syntax for that? – gakis Jul 18 '13 at 10:35
  • `$(selector).load('script.php', {'string': var})` – Pieter Jul 18 '13 at 10:55
  • I changed my code like this: var str = prompt("Please enter data of Column") var selr =jQuery('#list1').jqGrid('getGridParam','selarrrow'); $(selector).load('Updatestatus.php', {'string': str,'chbox[]': selr}) But it doesn't working.In php file i fetch the variables with _GET? – gakis Jul 18 '13 at 11:30
  • Take my code and replace 'string' by the name of the variable and 'var' by the variable. – Pieter Jul 18 '13 at 11:32
  • What should be written in php file to fetch the variables passed from jquery? – gakis Jul 18 '13 at 11:43
  • Just `$_REQUEST['variable_name']`. – Pieter Jul 18 '13 at 11:45
  • Could you check my code beacause it doesn't echo the variables:
    var str = prompt("Please enter data of Column")
        var selr = jQuery('#list1').jqGrid('getGridParam','selarrrow');
        $(selector).load('Updatestatus.php', {'string': str,'box[]' : selr })
    
    And in php:
    
    – gakis Jul 18 '13 at 11:59
  • You should replace `selector` by the selector of the element you want the response in. Please check this http://stackoverflow.com/questions/8674877/using-jquery-load-to-pass-a-parameter-to-and-call-a-php-function before, it's gives some working/good examples. – Pieter Jul 18 '13 at 12:10