Connecting Tech Pros Worldwide Help | Site Map

displaying a string that contains ' (quote)

Needs Regular Fix
 
Join Date: Mar 2007
Posts: 304
#1: Apr 14 '07
hi,

I have a string like this -> what a great 'score'

now when i try to display this in a div through javascript,

iddiv.innerText = str;

then i get an error that ')' is expected...

my only guess is that it encounters the first quote and considers that the end of the string,

so i would like to know as to how i could display the string correctly.

thanks,
gomzi.
Member
 
Join Date: Mar 2007
Location: The Netherlands
Posts: 37
#2: Apr 14 '07

re: displaying a string that contains ' (quote)


hi pal

first dont use innerText as firefox does not use it
as for your question
Expand|Select|Wrap|Line Numbers
  1. str='what a great \"score';
  2.  
  3. iddiv=document.getElementById('mydiv')
  4.  
  5. iddiv.innerHTML=str;
  6.  
well HTH
peace
Needs Regular Fix
 
Join Date: Mar 2007
Posts: 304
#3: Apr 14 '07

re: displaying a string that contains ' (quote)


Quote:

Originally Posted by DutchKingCobra

hi pal

first dont use innerText as firefox does not use it
as for your question

Expand|Select|Wrap|Line Numbers
  1. str='what a great \"score';
  2.  
  3. iddiv=document.getElementById('mydiv')
  4.  
  5. iddiv.innerHTML=str;
  6.  
well HTH
peace

thanks mate..ya.sure..will use innerHTML from now on. was wondering as to why firefox wasnt displaying it.so thanks for that tip.

just tried your solution ..works great!!
Needs Regular Fix
 
Join Date: Mar 2007
Posts: 304
#4: Apr 14 '07

re: displaying a string that contains ' (quote)


Quote:

Originally Posted by DutchKingCobra

hi pal

first dont use innerText as firefox does not use it
as for your question

Expand|Select|Wrap|Line Numbers
  1. str='what a great \"score';
  2.  
  3. iddiv=document.getElementById('mydiv')
  4.  
  5. iddiv.innerHTML=str;
  6.  
well HTH
peace


Tried it in firefox. the innerHTML solution doesnt help much..firefox is not displaying anything.. in ie and opera it works great..
Member
 
Join Date: Mar 2007
Location: The Netherlands
Posts: 37
#5: Apr 14 '07

re: displaying a string that contains ' (quote)


hmm works for me in IE and FF ?
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#6: Apr 16 '07

re: displaying a string that contains ' (quote)


Quote:

Originally Posted by gomzi

Tried it in firefox. the innerHTML solution doesnt help much..firefox is not displaying anything.. in ie and opera it works great..

There must be something else wrong with some other part of your code. For example, are you using document.all anywhere?
Reply