Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

add onclick on search button


Go to End


2 Posts   6064 Views

Avatar
bebabeba

Community Member, 193 Posts

5 August 2010 at 12:48am

Hi!

I create a form and I need ad a function with onclick. I prepare javascript file, I include this in my Page.php and i create the form like this:

How can I add onclick="scrivi_campo();" in my button?

function Ricerca() {

Requirements::javascript("themes/paddygreen/javascript/formsearch.js");

$fields1 = new FieldSet(
new TextField(
$name = "text",
$title = "Testo:",
$value = ""),
new HiddenField("error", "error", "1")
);

$validator = new RequiredFields('text');

$actions = new FieldSet(
new FormAction('doRicerca', 'CERCA')
);

return new Form($this, 'Ricerca', $fields1, $actions, $validator);
}

Avatar
3dgoo

Community Member, 135 Posts

5 August 2010 at 1:12pm

If you are using jquery, you can add the action to the button using javascript.

So in formsearch.js you could put the following:

;(function($) {
$(document).ready(function(){

	$('#whatever_button_id').click( function() {
		scrivi_campo();
	});

});
})(jQuery);