I need to add some new options into select form after event "change" () occurs. My web is based on Drupal 5.12.

Is jQuery the right way? Must I use AHAH? Is avaible some sample?

Thank you very much.

Twardowski

Comments

hershel’s picture

This can be done in jQuery without AHAH, generally speaking. Check out http://docs.jquery.com/Events for jQuery events and http://www.texotela.co.uk/code/jquery/select/ for select box manipulation with jQuery.

twardowski’s picture

I read this before, but (I forgot to write it) I need befor get some data from DB and this data put into select form. I know how to put into select form some static data.

twardowski’s picture

is there a way how to get data from DB "from" JS (is there a convenient Drupal function) code.

hershel’s picture

There is more than one way to do this. What form exactly do you want to change?

twardowski’s picture

I have got this form:

$form['language'] = array(
        '#type' => 'select',
	'#title' => t('Language'),
        '#options' => get_languages(),
        '#description' => t('Select the language you will add new translation.'),
	'#attributes' => array('style' => 'width:200px;', 'class' => 'language-array'),	
);

And I would like to change anoher form:

form['terms'] = array(
    '#type' => 'select',
    '#title' => t('Terms in selected language'),
    '#options' => array('a', 'ba', 'cada'),
    '#size' => 20,
    '#prefix' => '<div id="terms-select">',
    '#suffix' => '</div>',
    '#attributes' => array('style' => 'width:500px;', 'class' => 'terms-array'),
    '#multiple' => FALSE,
    '#description' => t('Select concept to translate.')
);

and I would like to add/change data (selected from DB, non static) in this form, when first form is changed.

Thank you very much!

twardowski’s picture

I tried something like this

$items[] = array(
    'path' => 'ontotranslate/simple_js', 
    'callback' => 'ontotranslate_simple_js',
    'type' => 'CALLBACK',
    'access' => true,
);  

And JavaScript code, that call this url:

if(Drupal.jsEnabled){
$(document).ready(function() {
$('select.terms-array').change(function() {
alert( "terms changed");
});*/
});
}

function ontotranslate_simple_js() {
    print drupal_to_js(array('score' => 10, 'ahoj' => 12)); //for example
    exit();
}

But everything that happened is: blank page only with this text:
{ "score": 10, "ahoj": 12 }