开发者

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

开发者 https://www.devze.com 2023-02-20 07:30 出处:网络
I have an update page with radiobutton \"Alternate Addresses\". If the radiobutton has \"Yes\" value, There would be altenate addresses for client.

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

精彩评论

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