views:

1066

answers:

2

Hi,

I am using Spring Forms for my web application. For nested properties, the form tag generates the input elements having id / name in form of .

For example, Person is the command class and Address is contained into its address field then the city element would be,

<input type="text" id="address**.**city" name="address**.**city" />

now, the problem is whenever I try to get its value using jQuery,

$("#address.city").val();

jQuery fails to select any appropriate element !

Please let me know any solution.

Thanks in advance.

+12  A: 

Try this:

$("#address\\.city").val();

From the documentation:

Note: if you wish to use any of the meta-characters described above as a literal part of a name, you must escape the character with two backslashes (\). For example:

#foo\\:bar
#foo\\[bar\\]
#foo\\.bar
nickf
'ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".")' - http://www.w3.org/TR/html401/types.html#type-name
insin
+4  A: 

$('[id="address.city"]') will also work

redsquare