0

I'm adding an hidden input as something in a select is choosen, using the onchange event with some jsp vars. I add some text to the div I'm working on but there are too many quotes and double quotes so I don't understand how to do it. Does anyone have any idea?

<select name="opt_name%>" onchange="$('#dati_opzioni').append('<input type="hidden" name="optdesc_'+<%=opt.getCdOpzione()%>+'" value="'+<%=optLabel%>+'_'+this.options[this.selectedIndex].text+'"/>');">

tony danza
  • 306
  • 7
  • 22
  • http://stackoverflow.com/questions/8007672/escaping-the-double-quote-that-is-in-the-attribute-of-an-html-tag – Dogbert Jun 24 '13 at 14:55
  • 3
    Wouldn't it be nicer and more readable to use event listeners instead of inline handlers? – DCoder Jun 24 '13 at 14:58

2 Answers2

1

Try using html entities for double quotes (as & quot; without blanks) inside the onchange="..."

<select name="opt_name%>" onchange="$('#dati_opzioni').append('<input type=&quot;hidden&quot; name=&quot;optdesc_'+<%=opt.getCdOpzione()%>+'&quot; value=&quot;'+<%=optLabel%>+'_'+this.options[this.selectedIndex].text+'&quot;/>');">
Packet Tracer
  • 3,884
  • 4
  • 26
  • 36
  • 1
    Won't work, attributes don't use `\\` escape sequences. http://stackoverflow.com/questions/8007672/escaping-the-double-quote-that-is-in-the-attribute-of-an-html-tag – Dogbert Jun 24 '13 at 14:56
0

try this:

<select name="<%=opt_name%>" onchange="$('#dati_opzioni').append('<input type=""hidden"" name=""optdesc_'+<%=opt.getCdOpzione()%>+'"" value=""'+<%=optLabel%>+'_'+this.options[this.selectedIndex].text+'""/>');">
Ani
  • 4,473
  • 4
  • 26
  • 31