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, biapar, Willr, Ingo, swaiba, simon_w

add onclick on search button


Reply


2 Posts   5559 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, 133 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);