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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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   5874 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);