EasyUI Forum
November 05, 2025, 04:18:36 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: combobox select, how to fire a AJAX call to pass a value to php  (Read 13069 times)
WillySis
Newbie
*
Posts: 1


View Profile
« 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.

« Last Edit: June 02, 2015, 01:33:25 AM by WillySis » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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
  }
});
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!