How would one go about doing this in drupal?

Comments

loze’s picture

Allow me to elaborate.
I have created a form field module. Its a simple select box with a custom query to populate its options.
it is set to "unlimited" values in my content type, so i can "add new item" and order them.
This works perfect.

What im trying to do is add a onchange event to each select box so using jquery i can display details about the selected option (each option references some other node on the site).

Can someone point me in the right direction?
thanks

kishorevaishnav’s picture

Hi,

Did you get any solution for this, if possible please share :-)

regards,
KV

loze’s picture

If I remember correctly, I added js in the head (or a .js file), that on load, set the onchange of the form element.
This allowed me to add the js w/o changing the form markup.

$(document).ready(
    function(){
       $('elementID').change(function(){
	   //do something
	});			
    });	

I think you can also use the [#attributes] for the form element. $form['myelementid']['#attributes'] = array('onchange' => 'myJsFunction();');
which will put the onclick inline. <select id="myelementid" onchange="myJsFunction();"> ... </select>

http://api.drupal.org/api/file/developer/topics/forms_api_reference.html...
http://docs.jquery.com/Main_Page

czeky’s picture

subscribing

suganyaM’s picture

I have created a cck field. In the node-form it is a select box, and i want to include a onchange event for the field. I tried to include using '#attributes" but it doesnt work out for me.

The code :
$form['field_first_level_category']['#attributes'] = array('onchange' => 'retrieveNextLevel();');
I am using '#attribute' to pass php values to js function.

Could any one please help me to get it done?

h_shr62’s picture

Sorry there is a question:

I want to add this attribute, but I don't know where!
would you please inform me exactly where can I add this $form['myelementid']['#attributes'] = array('onchange' => 'myJsFunction();');

harnarayant’s picture

You can define conditional field from cck and select the conditional filed from lest of field on add form.

YK85’s picture

I am needing to select checkboxes on event 'hover' or 'mousedown' so that a user can click and drag the mouse over checkboxes which will then be checked/unchecked.

Can anyone help me with this?