EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: WillySis on June 02, 2015, 12:55:00 AM



Title: combobox select, how to fire a AJAX call to pass a value to php
Post by: WillySis on June 02, 2015, 12:55:00 AM
I'm a newbee to EasyUI but it looks great and it has many cool features.

I have a combobox which should fire a AJAX call when a new selection is made. The code is working with a native combobox (onchange), but I cant get it work properly with a EasyUI combobox.

The combobox is filled from a database with id's and a corresponding text. If there is a value in the database the corresponding field will be selected by default.This is all done in PHP. Nothing complicated here.

When the user selects another item it's id has to be sent to the server. This has to be done in AJAX. For a combobox with both name and id set to owner_org I setup a jquery AJAX script:

Code:
$(document).ready(function() {

  $('#owner_org').select(function(){
        var value = $(this).val();
        $.ajax({
                type: 'POST',
                url: 'php/combobox_choice.php',
                data: {'sv':'owner_org','choice':value},
                success: function(data){alert(data)}
            });
   });

 });

This schould post two variables ("sv", set to "owner_org" and "choice", which shoul be set to the value (id) of the selected item).
This should fire a php script "php/combobox_choice.php' :

Code:
<?php
session_start
();
// One routine for al comboboxes
// Parameter  sv  = name of session variable
//  choice  = chosen item (ID)

echo 'Session id='.session_id().' / ';
 if (isset(
$_POST['sv'])) {
echo ' Session variable :'.$_POST['sv'].' ';
if( isset($_POST['choice']) ) {
    
$_SESSION[$_POST['sv']] = $_POST['choice'];
echo '= '.$_SESSION[$_POST['sv']];
 
}
}
 
?>

The echo parts are put in to see what it is doing but are no part of the routine itself.

All the code works with native comboboxes (the AJAX call is then "change" instead of "select".

Can somebody please help me out.



Title: Re: combobox select, how to fire a AJAX call to pass a value to php
Post by: stworthy on June 02, 2015, 07:04:31 PM
If you are using the combobox component, please use the 'onChange' event instead.
Code:
$('#owner_org').combobox({
  valueField: ...,
  textField: ...,
  onChange: function(value){
    // ajax call
  }
});