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.

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   5741 Views


Community Member, 193 Posts

5 August 2010 at 12:48am


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() {


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


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($) {

	$('#whatever_button_id').click( function() {