I want to call a function on button click with a dynamic parameter passed to that function.
HTML:
<button onclick=getvalue(val['id']):void(0);>Click</button>
JavaScript:
function getvalue(id) {
alert(id);
}
I want to call a function on button click with a dynamic parameter passed to that function.
HTML:
<button onclick=getvalue(val['id']):void(0);>Click</button>
JavaScript:
function getvalue(id) {
alert(id);
}
You need to put the attribute in quotes because there are quotes in the value. Also, you have a syntax error with :void(0);
after the function call.
<button id="button1" onclick="getvalue(this.id);">Click</button>
Or you can give the element an ID and bind the click handler in jQuery.
<button class="mybuttons" id="button1">Click</button>
<script>
$("#mybutton").click(function() {
getvalue(this.id);
});
</script>
Refer this.....
<script type="text/javascript">
function display(el) {
var id = $(el).attr('id');
alert(id);
}
</script>
<input id="btn" type="button" value="click" OnClick="display(this);" />
i did that it was a tiny mistake
<a href="#" class="pull-right button uppercase" onclick="getvalue('+val['id']+');">Click</a>
function getvalue(val){
alert(val);
}
one more thing if you don't want to load your page just replace # > javascript:void(0) in href .