in the following code i have a html radio and a java script code. when the radio is checked the text of Lable1 text will be change to "test". my question is that how can i do the same thing for asp:radiobutton that run on client side?
<input id="Radio1" checked="true" onmousedown="fun()" name="R1" type="radio"
value="V1" /></p>
<script>
function fun()
{
document.getElementById("Label1").innerHTML.text = "test";
}
</script>
If this is classic ASP you could use this:
<asp:RadioButtonList ID="RadioButtonList" runat="server" onclick="fun();">
<asp:ListItem Text="JavaScript" Value="JavaScript</asp:ListItem>
<asp:ListItem Text="C#" Value="C#"></asp:ListItem>
<asp:ListItem Text="ASP.Net" Value="ASP.Net"></asp:ListItem>
</asp:RadioButtonList>
<script type='text/javascript'>
function fun()
{
document.getElementById("Label1").innerHTML.text = "test";
}
</script>
I would recommend using the onchange event if this is just html and javascript:
http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onchange
Set the ClientIDMode to "Static" so the ID doesn't change.
<asp:RadioButton id="R1" ClientIDMode="Static" runat="server" onmousedown="fun()" Value = "V1"></asp:RadioButton>
I only know how to do it using Jquery, so your script block would look like this
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<script>
function fun() {
$('label[for="R1"]').text('your new text');
}
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.