Jump to:

23478 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » add onclick on search button

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

Page: 1
Go to End
Author Topic: 5501 Views
  • bebabeba
    Avatar
    Community Member
    192 Posts

    add onclick on search button Link to this post

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

  • 3dgoo
    Avatar
    Community Member
    133 Posts

    Re: add onclick on search button Link to this post

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

    5501 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.