PDA

View Full Version : Java script Var + double quotes



ReenaJ
12-20-2007, 11:49 AM
Hi,

How to add double quotes in java script var. I got error if I give double quotes within "".but It's accepting if I give single quotes within "".
snippet:

for (i=0;i<Ca.length;i++){

getModel =getModel +"'"+Ca.options[i].text+"'"+",";

}

var getST=getModel+")"+""";

Thanks in Advance!
Reena.

Actinia
12-20-2007, 12:36 PM
Just escape the double quote with a backslash:


getModel =getModel +"\""+Ca.options[i].text+"\""+",";

John Rostron

Philip M
12-20-2007, 12:40 PM
You can have double quotes " within single quotes ' or vice versa.

for (i=0; i<Ca.length; i++) {
getModel = getModel + "'" + Ca.options[i].text + "'" + ",";
}
var getST= getModel +')' + '"';

BTW, the time to say "thanks" is afterwards, not beforehand which gives the impression that you take other people's assistance for granted.