...

View Full Version : Java script Var + double quotes



ReenaJ
12-20-2007, 10: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, 11:36 AM
Just escape the double quote with a backslash:


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

John Rostron

Philip M
12-20-2007, 11:40 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum