This is a migrated thread and some comments may be shown as answers.

Button click calling javascript method

4 Answers 1434 Views
Button (Mobile)
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 04 Aug 2012, 02:56 AM
Hi,

I have a "sign in" button on a view and when a user clicks on it, I want it to run a javascript method. It seems simple and I have a sample one page app which works. However my actual app is several pages and for some reason the same html doesn't work when I copy it from the sample page to the real app. I'm currently trying 3 ways to call the javascript method, but i think the first one is the right way.

<data-role="button" data-click="signInButton">Sign In</a>
<data-role="button" href="javascript:signInButton();">Sign In 2</a>
<data-role="button" onclick="signInButton()">Sign In 3</a>

And the javascript is currently very simple, just popup and alert so I know the method got called and navigate to another view.

function signInButton(e{
    alert('signInButton');
    app.navigate("#phoneMain");
}

Here is the current app http://jsfiddle.net/jwhitmer/vsPye/

A few other forum posts helps me get this far. It runs on iPhone, iPad, Android phone and Blackberry phone. I'm amazed at what Kendo UI can do with so little coding on my part.

Thank you for any guidance,
Jason

4 Answers, 1 is accepted

Sort by
0
Accepted
Petyo
Telerik team
answered on 06 Aug 2012, 07:12 AM
Hello Jason,

The first button uses the correct syntax for event handling. There is a catch in jsFiddle though, which scopes the functions in it javascript panel. I updated your jsfiddle to output the scripts in the body, and it works now.

http://jsfiddle.net/vsPye/47/

Greetings,
Petyo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jason
Top achievements
Rank 1
answered on 06 Aug 2012, 01:14 PM
Thank you, Peyto. Its working great now.
0
John
Top achievements
Rank 1
answered on 08 Nov 2012, 07:06 PM
Can you pass an argument in the Kendo UI data-click? What is the best practice on passing arguments? 

<a data-role="button" data-click="updateShowButtonGroup('Test');">test</a>


<script> updateShowButtonGroup(tmp){

alert(temp);
}
</script>


thank you,
richard
0
Michael Rogers
Top achievements
Rank 2
answered on 14 Nov 2012, 09:43 PM
I also have the same question as John.  When i do it this way the button only works if i click on the very edges of it if i click on the text it never fires the JS

Thanks
Michael

<ul data-role="listview" data-style="inset" id="lvRASServers" data-bind="source: RASServer" data-template="RASServers-template" >
                <script id="RASServers-template" type="text/x-kendo-template">
                                             
                    ${RASServerTitle}
                    <a data-role="button" class="rdpButton" onClick="startRDP('${RASServerHostname}')">Connect</a>                                              
                     
                </script>
            </ul>
Tags
Button (Mobile)
Asked by
Jason
Top achievements
Rank 1
Answers by
Petyo
Telerik team
Jason
Top achievements
Rank 1
John
Top achievements
Rank 1
Michael Rogers
Top achievements
Rank 2
Share this question
or