2

I can't figure out why I can't get an html element like this:

<input name="ctl00$body$frmViewODL$ListViewParametri$ctrl0$txtParametroValoreNum" type="text" value="1" id="body_frmViewODL_ListViewParametri_txtParametroValoreNum_10  " class="boxNum" style="width: 60px">

with this jQuery:

$('#body_frmViewODL_ListViewParametri_txtParametroValoreMax_10  ')

I have tried removing/adding the spaces at the end :-)

PS: If i try

document.getElementById('body_frmViewODL_ListViewParametri_txtParametroValoreMax_10  ')

it is ok.

EDIT

The complete code is a little more complicated...

I have a ListView and I use the ClientIDRowSuffix to let asp.net append the Record key to the id of the control. I want to update an array of values(record) in a single post.

So In html I have an array of TextBox, like this:

<input name="ctl00$body$frmViewODL$ListViewParametri$ctrl0$txtParametroValoreNum" type="text" value="1" id="body_frmViewODL_ListViewParametri_txtParametroValoreNum_10  " class="boxNum" style="width: 60px">
<input name="ctl00$body$frmViewODL$ListViewParametri$ctrl1$txtParametroValoreNum" type="text" value="2" id="body_frmViewODL_ListViewParametri_txtParametroValoreNum_11  " class="boxNum" style="width: 60px">
<input name="ctl00$body$frmViewODL$ListViewParametri$ctrl7$txtParametroValoreNum" type="text" value="8" id="body_frmViewODL_ListViewParametri_txtParametroValoreNum_23  " class="boxNum" style="width: 60px">
...
James Montagne
  • 77,516
  • 14
  • 110
  • 130
spiderman
  • 1,565
  • 2
  • 16
  • 37

2 Answers2

3

Actually the problem might be jQuery parsing the selector with trailing space. Since usually spaces separate different parts of a selector, jQuery might not treat this trailing space as something that relates to # part. To make sure it understands that space is a part of an ID, you might want use attribute selector instead:

$("[id='body_frmViewODL_ListViewParametri_txtParametroValoreNum_10  ']")
Andrei
  • 55,890
  • 9
  • 87
  • 108
1

Better way is let the aspx page parser write what ever it comes and apply attribute selector.(Thanks to @James Montagne comment on a question)

$("[id='<%= txtParametroValoreNum.ClientID %>']")
Murali Murugesan
  • 22,423
  • 17
  • 73
  • 120