2

So I am trying to find the value of a text-box whose ID looks like:

id="filter[default][did.did]"

I am trying: var did1 = $('#filter[default][did.did]').val(); but this is not working. Can someone help me out please?

I probably should have said this initially but there are three textboxes that all have that same ID. I tried escaping the characters like you guys said and I am still getting undefined. However each of the textboxes have a unique name: filter[default][did.did1_DID_] could this be used instead?

EDIT: I am still trying to figure this out. I need to get the value using the name and the other example appears it is setting the value instead of getting the value. I tried var did1 = $('input[filter\\[default\\]\\[did.did1_DID_\\]]').val(); and this is not working

var did1 = $('input:text[name=filter\\[default\\]\\[did.did1_DID_\\]]').val();  

ended up working using the example above

Sparky
  • 98,165
  • 25
  • 199
  • 285
bdevinedev
  • 58
  • 6

1 Answers1

4

Try to escape the meta-characters,

 var did1 = $('#filter\\[default\\]\\[did\\.did\\]').val(); 

[ , ] and . are meta characters of jquery, you have to escape it while using it as a selector.

DEMO

Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130