I was going through some java code(which uses playframework) that provides some shopping cart functionality.The html page contains some javascript (it uses jquery) which is something I have very little knowledge of.Looking through the html,I found a table like this
<table>
...
<td>
<a href="" onclick="return addItem(${item.id});">buy</a>
</td>
...
</table>
(The template uses ${} to get dynamic values thru playframework template language)
In the entire code ,the only addItem(itemId) method I could find was in the ShoppingCart class which has this signature
public void addItem(Item item) {
...
}
When I searched for onclick ,I found this page onclick doc,which gives the syntax of onclick as
onclick="SomeJavaScriptCode"
Going thru all the javascript code(it uses jquery and ejohn-templating)I couldn't find any method like 'addItem'
So,how does the onclick work?How would it know which method to invoke?Will it look in the entire code (javascript and java)to find a matching method?