- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
i added this function into app.js
function showID(productID)
{
alert(productID);
}
how to call from anchor?
this is not working:
<a href="javascript:showID(1);">open product 1</a>
- Tags:
- HTML5
- Intel® XDK
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Are you writing this from scratch or using the Design tool? If you are using the Design tool, then the Interactivity pane will help you set up scripts on elements.
Many developers prefer to keep the content and any interactive logic separate. So instead do this:
<!DOCTYPE html> <html> <head> <!-- let's use jQuery. Makes this a little easier --> <script src="jquery.js"></script> <script> function showID(productID) { console.log("product id:", productID); // I prefer console.log to alert. alert(productID); } $(document).ready(function() { $("#my-link").click(function(){ showID(1); return false; }) }) </script> </head> <body> <a href="#" id="my-link">Click Me</a> </body> </html>
If you haven't used jQuery, you can read more here: https://learn.jquery.com/about-jquery/how-jquery-works/
I don't necessarily recommend jQuery for all projects, but in this case I think it'll help make things a lot easier. Especially if you are newer to web development.
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
in the page are many links, each link is generated from a webservice e represents a product. Clicking on it the app navigates into detail page so need to pass the ProductId to showID function. How to pass the product id using jquery ?
Anyway this code is working fine:
<a href="javascript:void(0);" onclick="showID
(1);">some product</a>
<a href="javascript:void(0);" onclick="showID
(2);">another product</a>

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page