0

I need to select an item with an id value that is not always the same (depending on amount of radio buttons set by Code Behind of ASP.NET WebForms). What is unique is the valuethat belongs to the input field.

<input id="ctl00_ContentPlaceHolder1_RadioButtonList_2" type="radio" 
    name="ctl00$ContentPlaceHolder1$RadioButtonList" value="21" />

How can I obtain this input element with JavaScript that works in IE8?

user2609980
  • 10,264
  • 15
  • 74
  • 143

1 Answers1

1

Yes, It is possible. You can do it by following way:-

$(function(){
    element = $('input[value="The unique value"]');
    /*do whatever you want with this element*/
});

follow this answer for more info: jquery find element by text

Community
  • 1
  • 1
Gaurav Kalyan
  • 1,897
  • 2
  • 14
  • 21
  • Sorry, I changed the question a bit. But this works as well. The value of the element is better though. – user2609980 Nov 28 '14 at 14:18
  • remove quotations around 21, then it should work. Here is an example : http://jsfiddle.net/4tu9Lotg/2/ – Gaurav Kalyan Nov 28 '14 at 15:01
  • Ah thanks. Then perhaps it does not select the full element? I have to see if it is checked. E.g., `var cancelOpeningRadioButton = $('input[value='21']'); if(cancelOpeningRadioButton.checked) [do something];`. – user2609980 Nov 28 '14 at 15:02
  • It generally selects the whole element. I tried to make a jsfiddle as you stated above, please tell me if it works: http://jsfiddle.net/4tu9Lotg/4/ – Gaurav Kalyan Nov 28 '14 at 15:10
  • It definitely works, thanks a lot. Something else must be going on. I will investigate. Thanks a bunch! – user2609980 Nov 28 '14 at 15:11
  • I was not running Visual Studio as admin... It was not allowed to access jquery in debug mode on my C:\ drive. Thanks again! – user2609980 Nov 28 '14 at 15:57
  • Ended up doing something like this: html id = `radiobuttonlist.clientid + "_" + radiobuttonlist.items.indexof(radiobuttonlist.items.findbyvalue([myvalue]))`. Suits asp.net better. – user2609980 Nov 28 '14 at 18:39