By nikifi on
I am just in the very beginning stages of learning module development. I am stuck at something very basic. I know it's simple (I think) but I still cant find an answer. Here is an implementation of the form api:
$form['create_fields']['custom_multitext_field'] = array(
'#type' => 'button',
'#value' => t('Some text'),
);
Now say I want to write a JQuery statement to act on clicking the button. I gather that the syntax is something like this:
$("some selector").onclick(function(){alert('test')});
With some selector being a CSS selector. My question is, what would be the selector in the form implemented above, or how do you include the element. Thanks in advance.
Comments
The selector id for your field is edit-custom-multitext-field
$('#edit-custom-multitext-field').click(function() {
alert('test');
});
Mostly it will replace the underscore into hyphen and start with edit.
Better use firebug to find the selectors.
using #attributes is more efficient
Here is an example..
same way you can assign classes or id for particular form element
eg:
'#attributes' => array('casss' => 'myclass', 'id' => 'my_form_element' );
Best Regards,
Rajan
Use "#prefix" and "#suffix"
Hi,
You can use "#prefix" and "#suffix" (form api) to add html markup to your button.
Thanks
Thanks for all the help! I got it to work.