I'm a newbie to all this ASP.NET MVC stuff, and I was making some tests for my project. I wanted to ask how is it possible to introduce a javascript function call from the html.radiobutton function. For example, how would you declare this:
<input type="radio" name = "Kingdom" value = "All" onclick="GetSelectedItem(this);" checked ="checked" />
with html.radiobutton. I've been looking for some documentation, but I don't really get to understand, I guess it has something to do with the html object attributes, but don't really know the syntax and I haven't found any example.
Thank you all in advance :) vikitor
Define the attributes as an anonymous object.
<%= Html.Radiobutton( "Kingdom",
"All",
true,
new { onclick = "GetSelectedItem(this);" } ) %>
or better yet, apply the handler unobtrusively with javascript (ex. uses jQuery).
<%= Html.RadioButton( "Kingdom", "All", true ) %>
<script type="text/javascript">
$(function() {
$('input[name=Kingdom]').click( function() {
GetSelectedItem(this); // or just put the code inline here
});
});
</script>
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