Reputation: 41
I have a problem sending and receiving data from a button to a modal form in bootstrap.
Inside my button tag I have:
data-comment=<%=Comentarios.listUltimos().get(i).getComentario() %>
And then I take that data with a java script code in the event on click, where I fill the form.
var myComentario = $(this).data('comment');
document.getElementById("myModalComment").value=myComentario;
It works fine but It only takes the first word of the content I have in my Database.
Upvotes: 0
Views: 1095
Reputation: 30595
Looks like you're inserting the data as-is without proper quoting:
<sometag attr=foo bar baz>
Which parses into a tag with attributes:
attr="foo"
bar
baz
When what you really meant was:
<sometag attr="foo bar baz">
What you want to do is surround the <%...%>
with quotes and proper escaping:
data-comment="<%=Comentarios.listUltimos().get(i).getComentario().replace("\"", "\\\"") %>"
Upvotes: 1