Button call javascript with parameters

2 posts, 0 answers
  1. Gilbert van Veen
    Gilbert van Veen avatar
    74 posts
    Member since:
    Oct 2009

    Posted 31 Aug Link to this post

    Is it possible to call a Javascript with parameters when the user presses a button in the toolbar?

    I can use the .Click() and the javascript is called but I can't figure out how to pass the parameters?

    I als tried.....

     .Items(items =>
        {
            items.Add().Type(CommandType.Button).Text(Model.ToolbarSettings.NewButton.Text).Icon("plus")
                .Hidden(!Model.ToolbarSettings.NewButton.IsVisible).Enable(Model.ToolbarSettings.NewButton.IsEnabled)
                .HtmlAttributes(new { type ="button", Id = "aa" })
                .Click("onClick")

    But how can I read the Id value in the javascript?

    I want pass two parameters to the script (action/controller)......

     

  2. Stefan
    Admin
    Stefan avatar
    1147 posts

    Posted 04 Sep Link to this post

    Hello Gilbert,

    In general, I can suggest setting the ID using the ID property of the button, then it will be available in inside the click event under e.id:

    items.Add().Type(CommandType.Button).Text(Model.ToolbarSettings.NewButton.Text).Icon("plus")
               .Hidden(!Model.ToolbarSettings.NewButton.IsVisible).Enable(Model.ToolbarSettings.NewButton.IsEnabled)
               .HtmlAttributes(new { type ="button", Id = "aa", customAttr = "test"})
               .Id("aa")
               .Click("onClick")

    Then any other custom attributes can be retrieved inside the event using jQuery and the e.target element:

    function onClick(e) {
            console.log($(e.target).attr("customAttr"))
            console.log(e.id)
    }

    I hope this is helpful.

    Regards,
    Stefan
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top