开发者

How to retrieve radiobutton selected value on asp: button click in javascript

I have an update page with radiobutton "Alternate Addresses".

If the radiobutton has "Yes" value, There would be altenate addresses for client.

If radiobutton has "No" value, there won't be any alternate addresses.

In update page, if supplier changes radiobutton value from "Yes" to "No" and clicks asp:Button "Update", all alternate addresses will be deleted.

I want to show a confirm messagebox on Update button click. But i am not being able to retrieve radiobutton selected value in javascript.

 var list = document.getElementById("radios"); //Client ID of the radiolist  
var inputs = list.getElementsByTagName("input");  
var selected;  
for (var i = 0; i < inputs.length; i++) 
{       
if (inputs[i].checked)
 {           
selected = inputs[i];           
break;        
} 

This code works fine with html buttons. But I want 开发者_开发知识库code for asp:Button onClientClick. Please Help. Thanks in advance


You can attach javascript from code behind as well like.

ASPNET_Server_Control.Attributes.Add("onclick", "return yourJSFunction();")

You should make sure you return false in asp button, if you dont want a post back to happen.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜