0

Info's: I have some javascript code that i will show below, who i'm having problem with quotes.

html = [];
style = 'class=odd';
html.push('<li '+style+' onclick=SelectItem("'+ele.id+'","'+idItem+'","'+dsItem+'","'+qtItem+'"); >'+id+' - '+$iObjItensListaVenda.result.ds_item[i]+'</li>');

I have strings that i get from a JSON Object, as you see above.

Problem: But when i'm trying to place it as a Function Parameter on the onClick event of the <li> element, my resulting html <li> element becomes totally unformatted like that:

<li natural,"150");="" white="" american="" onclick="SelectItem("descItem1","2",TELHA" class="odd">00002 - TELHA AMERICAN WHITE NATURAL</li>

What do i want: i need a solution like a function, maybe already exists in jQuery, to Quote my String. Like a QuoteStr("s t r i n g"); to become ""s t r i n g"".

Maybe you're complaining about:

  1. The variable ele is a html <input> element.
  2. The variable idItem contains only numbers, they come from a JSON Object.
  3. The variable dsItem its a string containing Item Description, it comes from the JSON Object too.
  4. The variable qtItem contains only numbers, it is the quantity of the items, it comes from the JSON too.
Paulo Roberto Rosa
  • 3,071
  • 5
  • 28
  • 53
  • These are no problems. Please see my answer. – Felix Kling Jan 20 '14 at 18:35