I am trying to pass an object to a javascript function which should trigger when a link is clicked. But unfortunately I am not able to get it working.
Here is the code on my jsp file for the same:
<script type="text/javascript">
$(document).ready(function() {
function tryToDoItTwice(obj) {
var check = obj;
if(check == null) {
return true;
}
else {
alert("You're not allowed to do this twice!");
return false;
}
}
});
</script>
<a href="<c:url value="/somepath" />" onclick="javascript: tryToDoItTwice(${foo});">Try to do it twice</a>
Here foo refers to an object of type Foo.
Could someone help me understand what am I doing wrong here?
EDIT: Foo is a java object. and ${foo} is a reference variable referring to Foo java object.
Thanks.
javascriptinside the onclick attribute. And, give us the error message.$ is not definedis not defined when you don't include jquery.js.