I have a scenario where i need to pass randomly generated id to the javascript function, but javascript function is not recognizing. Iam using dojo enhanced grid. Below is the code:
function(value, rowIndex) {
var Id = this.grid.getItem(rowIndex).ID;
alert("ID+ " + Id);//retriving the id value correctly
return "<img src=../img/smiley.jpg width=\"20\" height=\"20\" onClick=\"showData(\''+Id +'\')\" class=\"display\">" ;
};
<script>
function showData(id){
alert(id);//unable to get the id here..
}
</script>
Thanks in advance.
The quotes in the listener are messed up. I tend to use double quotes for HTML and single for script, and nest as appropriate:
return '<img src="../img/smiley.jpg" width="20" height="20" onclick="showData(\'' + Id + '\');" class="display">';
Also, I much prefer to use lower case for all attribute names and to quote all values, not just those that strictly need it.
Finally, variable names starting with a capital letter are, by convention, reserved for constructors so you should use id
not Id
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With