0

I have a some text boxe with id that contains special character like '(' and ')' . when i am accessing value of this text boxe i am getting value as undefined .need solution of this problem ...

  <input type="text" id="header_COUNT(SUBJECT)"  onblur="javascript:setHeader();" disabled="disabled">

script is

function setHeader(){
var val=$('#header_COUNT(SUBJECT)').val();
console.log(val);

}
Ashish Panery
  • 1,196
  • 3
  • 13
  • 24
  • An ID can't contain those characters, at least not in HTML 4. [What are valid values for the id attribute in HTML?](http://stackoverflow.com/q/70579) – Pekka Nov 05 '12 at 10:48

4 Answers4

1

This is not such a complex selector. You can use getElementById:

var val=$(document.getElementById('header_COUNT(SUBJECT)')).val();
Amiram Korach
  • 13,056
  • 3
  • 28
  • 30
0

You can escape characters in jQuery with 2 backslashes \\

So reference it like:

$('#header_COUNT\\(SUBJECT\\)')

jsFiddle

Elliott
  • 2,669
  • 2
  • 23
  • 33
0

Use the following code

function setHeader(){
var val=$('input[id="header_COUNT(SUBJECT)"]').val();
console.log(val);
}
Ashwin Preetham Lobo
  • 1,856
  • 1
  • 14
  • 19
0

jsbin

var id_with_special_chars = 'header_COUNT(SUBJECT)';
var value =  $('input[id="'+id_with_special_chars+'"]').val();

alert(value);
Abhilash
  • 1,610
  • 9
  • 19