Reputation: 723
I have a label where the value Coeur D'alene is prepopulated. The label is defined as
<label for="otherSpokenLanguage" class="hide"><spring:message code="label.entity.otherSpokenLangugesInput"/></label>
Now the issue is when I am trying to do $("#otherSpokenLanguage").val();
I am getting only Coeur D
Is there any way I can get the whole value which is inside the label that is Coeur D'alene
Upvotes: 1
Views: 99
Reputation: 196187
My guess (without seeing the output html) is that the value
attribute is applied with single quotes '
and thus the quote in the text make the attribute end.
Something like
<input id='otherSpokenLanguage' value='Coeur D'alene' />
(see the problem ?)
You will have to make either the wrapper quotes be double "
(you will get the same problem if the value contains "
now)
<input id="otherSpokenLanguage" value="Coeur D'alene" />
or html encode the value so that the '
in it becomes '
<input id='otherSpokenLanguage' value='Coeur D'alene' />
Upvotes: 1
Reputation: 3071
Not 100% if you're trying to get the value of an input here, or the text within a label.
If the value of an input, then it seems clear that the attributes in the html are being wrapped in single quotes (') rather than double (") which I believe would solve the problem. Currently it looks like the ' is escaping the quotes.
So you would have something like this:
<input id="otherSpokenLanguage" value="Coeur D'alene" type="text" />
and:
alert($("#otherSpokenLanguage").val());
would give you the full value. See fiddle: http://jsfiddle.net/85Jzn/
If you are looking to get the text out of the label element, then you need to search for the label which does not have an id, and then get the text out of it. Something like this would be your html:
<label for="otherSpokenLanguage">Coeur D'alene</label>
and so your JS would be:
alert($("label[for=otherSpokenLanguage]").text());
and this would get the label text. See fiddle: http://jsfiddle.net/Lta6N/
Hope that helps.
Upvotes: 0