Removing quotes OR including quotes when using append

I have a variable, PRODUCT_CUSTOM_1_ and PRODUCT_NAME_ . This is suppose to grab the product options from the html that is being displayed. We have a few products that contain quotations, " and '. When we grab these strings and post them elsewhere, it cuts off at the ". I either need the " removed or included within us posting it elsewhere.

How can I remove or include the " and ' from the two variables into my hidden form iwantCheckoutForm?

An example of a product name: 1/8" x 40' roll of tape An example of the custom option: 1/8" black, 1/4" red

var BongoCheckout = {insertForm: function() {

var custom =new Array;
for(i=0;i< qtys.length ;i++){
        for(j=0;j< $($("td.ys_itemInfo")[i]).children().children().length; j++){
             custom[i]= custom[i]+"   "+$($($("td.ys_itemInfo")[i]).children().children()[j]).text();

$("#iwantCheckoutForm").append('<input type="hidden" name="PRODUCT_ID_'+(i+1)+'" value="'+codes[i]+'">');
$("#iwantCheckoutForm").append('<input type="hidden" name="PRODUCT_NAME_'+(i+1)+'" value="'+items[i]+'">');
$("#iwantCheckoutForm").append('<input type="hidden" name="PRODUCT_PRICE_'+(i+1)+'" value="'+price[i]+'">');
$("#iwantCheckoutForm").append('<input type="hidden" name="PRODUCT_Q_'+(i+1)+'" value="'+qtys[i]+'">');
$("#iwantCheckoutForm").append('<input type="hidden" name="PRODUCT_CUSTOM_1_'+(i+1)+'" value="'+custom[i]+'" /> ');

if (per_item_shipping) {
$('form[name="iwantCheckoutForm"]').append('<input type="hidden" name="PRODUCT_SHIPPING_'+(i+1)+'" value="'+shipping_cost.toString()+'"> ');
} else {
$('form[name="iwantCheckoutForm"]').append('<input type="hidden" name="PRODUCT_SHIPPING_'+(i+1)+'" value="'+shipping_cost_breakdown+'"> ');

I know that this is a duplicate question sort of, but i couldn't quite figure out how to implement the 10+ suggestions into my current script. I just can't seem to include the regex argument, without the script from breaking. I tried to add it within the for loop.

        for(j=0;j< $($("td.ys_itemInfo")[i]).children().children().length; j++){
             custom[i]= custom[i]+"   "+$($($("td.ys_itemInfo")[i]).children().children()[j]).text(custom.replace(/\"/g, ""));

Blame that on me still being a n00b, and blame that on my ADD. I suppose I just don't know where I need to add .replace(/\"/g, "") as this code seems to be working for others.


Instead of creating HTML code for an element, just create the element and set the value. That elliminates all problems with escaping characters:

  $('<input>', { type: 'hidden', name: 'PRODUCT_NAME_'+(i+1) }).val(items[i])

use function

function makeInput(name,value) {
 var tmp = $('<input type="hidden" />');
 tmp.attr('name', name);
 return tmp;


Need Your Help

How calculate the day of the week of a date in ruby?

ruby date

How calculate the day of the week of a date in ruby? For example, October 28 of 2010 is = Thursday

Java: Fastest way to make a local copy of an initial ArrayList?

java arrays arraylist

My code requires me to create a large (301x301x19 items) ArrayList that has some initial values (some are 0, some are 1, etc) every time I call a function. The starting values are always the same and

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.