0

I have this control in my page:

<telerik:RadTextBox ID="txtTitleMyLink" Runat="server"></telerik:RadTextBox>

This is how it looks when it's rendered:

<input name="ctl00$MainContent$popupAddMyLink$C$txtTitleMyLink" class="riTextBox riEnabled" id="ctl00_MainContent_popupAddMyLink_C_txtTitleMyLink" value="">

I want to get what user types after the page is loaded. I call the line below from a button. It works but I don't want to use it since it could be change based on the containers:

$("#ctl00_MainContent_popupAddMyLink_C_txtTitleMyLink").val();

How can I accomplish getting the value based on a string? These ones are not working:

$("[id*=txtTitleMyLink]").val();
$("[id*='txtTitleMyLink']").val();
$("[id*='txtTitleMyLink']").text();
$("[id*='txtTitleMyLink']").attr('value');
$('#txtTitleMyLink').val();
$('#txtTitleMyLink').text();
Ned
  • 1,055
  • 9
  • 34
  • 58
  • try **$('#txtTitleMyLink').val();** or try **$('#txtTitleMyLink').text();**. Since the telerik control (apparently) is altering the ID of your element, you may have to try and alter the jquerys selector using *ctl00_MainContent_popupAddMyLink_C_txtTitleMyLink* – jbutler483 Dec 19 '14 at 16:01
  • @jbutler483 `$('#txtTitleMyLink').val();` or `$('#txtTitleMyLink').text();` are not working. I edited my post – Ned Dec 19 '14 at 16:07
  • what about replacing that selector with the longer id? – jbutler483 Dec 19 '14 at 16:08
  • @jbutler483 It works as I mentioned in my question. However, I don't want to use the exact ID because it will change if somebody changes the name of the control `popupAddMyLink` – Ned Dec 19 '14 at 16:10
  • 1
    [see this](http://stackoverflow.com/a/609399/3436942) – jbutler483 Dec 19 '14 at 16:18
  • 1
    It works. I don't why asterisk (*) doesn't work but dollar sigh ($) works. Anyways, I'll select it if you post it as an answer. Thanks – Ned Dec 19 '14 at 17:46

1 Answers1

1

Instead of using the * (commonly used as 'all' in css), is slightly different in jquery. So, by using the $ (known as 'Jquery') will do as you want.

If you know the element type then: (eg: replace 'element' with 'div')

$("element[id$='txtTitle']")

If you don't know the element type:

$("[id$='txtTitle']")

So, in your case, you would look to use:

$("[id$=txtTitleMyLink]")

to select your id 'which contains the words txtTitleMyLink' into your jquery select statement.

jbutler483
  • 24,074
  • 9
  • 92
  • 145