Web Analytics Made Easy -
StatCounter Escape character for single quote problem - CodingForum

Announcement

Collapse
No announcement yet.

Escape character for single quote problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Escape character for single quote problem

    I keep getting a script error when I enter a string like this

    quotes[9]='This is what I\'m trying to say'

    Why doesn't this work? Every webpage I've seen says this works, but I get a script error every time.

    TIA,
    Reuben

  • #2
    damm, there was supposed to be a backslash in the string, right before the single quote. The board must have parsed it out.

    Comment


    • #3
      why not just go between quotes and double quotes like so

      quotes[9] = "This is what I'm trying to say"

      make sure you have your language parameter, set " \' " should work. next time just post your code.
      I would rather be a lion for a day than a lamb that lives forever.

      Comment


      • #4
        Are you getting this error when you're displaying the information on a page, or when you're writing it to a database?

        There are easy solutions for both situations!
        Former ASP Forum Moderator - I'm back!

        If you can teach yourself how to learn, you can learn anything. ;)

        Comment


        • #5
          Hi all,

          I'm getting this problem when writing to a div marker within a webpage. I'll paste the entire code below. The problem is that block of quotes[] assignments. When I put either single quote within a double quote assignment like
          quotes[0]="He's a dog." or when I use a single quote within a single quote assignment, like this
          quotes[0]='He\'s a dog." I get a script error. If I remove the single quote, it works fine.

          Thanks

          <!--
          var secs
          var timerID = null
          var timerRunning = false
          var delay = 1000
          var quotes=new Array()
          var whichquote
          var tempwhich

          quotes[0]='everything is purple.'
          quotes[1]='we kill Jesus again.'
          quotes[2]='the chickens inherit the Earth.'
          quotes[3]='it turns out the Jews were right.'
          quotes[4]='the lotto numbers are 21 5 3 25 33 17.'
          quotes[5]='dogs WILL play poker.'
          quotes[6]='Reubeeeeen ****s a like, totally cantankerous bovine carny.'
          quotes[7]='Cheez-Itz is people.'
          quotes[8]='iguanas are everywhere.'
          quotes[9]='Sony owns everybodys reproductive organs.'
          quotes[10]='America finally kicks Canadas ***.'
          quotes[11]='\"smell ya later\" does indeed replace \"Goodbye\".'

          function writetoLyr(id, message)
          {
          if (document.layers)
          {
          document.layers[id].document.write(message)
          document.layers[id].document.close()
          }
          else if (document.all)
          {
          eval("document.all."+id+".innerHTML='"+message+"'")
          }
          else
          {
          document.getElementById(id).innerHTML = message;
          }
          }

          function InitializeTimer()
          {
          // Set the length of the timer, in seconds
          secs = 4
          StopTheClock()
          StartTheTimer()
          }

          function StopTheClock()
          {
          if(timerRunning)
          clearTimeout(timerID)
          timerRunning = false
          }

          function StartTheTimer()
          {
          if (secs==0)
          {
          StopTheClock()
          PrintAMessage()
          }
          else
          {
          //self.status = secs
          secs = secs - 1
          timerRunning = true
          timerID = self.setTimeout("StartTheTimer()", delay)
          }
          }

          function PrintAMessage()
          {
          writetoLyr('testLayer','')
          while(tempwhich==whichquote)
          {
          tempwhich=Math.floor(Math.random()*(quotes.length))
          }
          whichquote=tempwhich
          setTimeout("WriteIt()",500)
          InitializeTimer();
          }

          function WriteIt()
          {
          writetoLyr('testLayer',quotes[whichquote])
          }

          function StartItOff()
          {
          whichquote=Math.floor(Math.random()*(quotes.length))
          tempwhich=whichquote
          writetoLyr('testLayer',quotes[whichquote])
          InitializeTimer()
          }

          function makevisible(cur,which){
          strength=(which==0)? 1 : 0.2

          if (cur.style.MozOpacity)
          cur.style.MozOpacity=strength
          else if (cur.filters)
          cur.filters.alpha.opacity=strength*100
          }

          //-->
          </SCRIPT>


          </html>

          Comment

          Working...
          X