asp.net - RadioButtonList and their 'Value' property -
i wondering 'value' property of item in radiobuttonlist.
if want value of selected radio button in list, these must unique or auto-select first item finds value i'm looking for. no duplicate values.
why this? i've looked around net, used them, , such know how working, know why works way.
if select item in list, knows item selected. button fills in, can index of item selected...so why doesn't go: "okay, selected item @ index x. want value? okay, let me access list, go item x , value."
i can think when want value of item, looking value rather index value?
update 1: in particular case doing this:
i have 1 radiobuttonlist has 3 items(radiobuttons) in it. following select...case occurs inside of button click.
select case radiobuttonlist1.selecteditem.text case "texta" case "textb" //this radiobutton has value of 200 case "textc" //this radiobutton has value of 200 end select
this works first case , 1 other. debugged, first , second cases went through fine. when selected third radiobutton, execute event, automatically select second radiobutton because has same value third, comes first in list.
changing 1 of identical values fixes this.
not sure understand, have html, script share? might have problem if you're using duplicate ids group radio button set; should use same name attribute. in case, if try value using selectelementbyid grab first one. since "want value of selected radio button in list", can array of same-named inputs (getelementsbyname) , loop through , 'checked' condition:
<input type="radio" name="cars" value="beamer" checked="checked">bmw<br><br> <input type="radio" name="cars" value="prius">prius<br><br> <input type="radio" name="cars" value="volvo">volvo<br><br> <input type="radio" name="cars" value="beamer">bmw<br><br> <input type="radio" name="cars" value="prius">prius<br><br> <input type="radio" name="cars" value="volvo">volvo<br><br> <p>selected car value , index:</p> <div id="selectedcar"></div><br><br> <button onclick="getval()">get value , index</button> <script> var getval = function(){ var cars = document.getelementsbyname('cars'); var result = document.getelementbyid("selectedcar"); (var = 0, length = cars.length; < length; i++) { if (cars[i].checked) { result.innerhtml = "value: " + cars[i].value + " , index: " + i; break; } } } </script>
Comments
Post a Comment