Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Posts
    172
    Thanks
    64
    Thanked 2 Times in 2 Posts

    How to escape quotes in this code?

    Code:
    <html>
    <body>
    <div id="link">
    <a href="http://www.facebook.com/">Facebook</a>
    </div>
    <script type="text/javascript">
    
    var addr=new Array();
    addr[0]="http://www.google.com/";
    addr[1]="http"//www.yahoo.com/";
    addr[2]="http://www.bing.com/";
    
    var rl=document.getElementById("link");
    var ri=Math.floor(Math.random()*3);
    
    
    rl.innerHTML= 
    
    
    </script>
    </body>
    </html>
    I got stuck in getting this to work (show random element of the array as a link with description)

    Code:
    rl.innerHTML='<a href="addr[ri]">addr[ri]</a>';
    This is showing addr[ri] on a page and directs to www.domain.com/addr[ri]

    Thank you in advance for any info.
    Last edited by joliett89; 10-08-2011 at 10:32 AM.

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    This doesn't have anything to do with escaping quotes but rather with string concatenation (the + operator). What you want to do is concatenate the following strings

    1. <a href="
    2. The content of addr[ri]
    3. ">
    4. The content of addr[ri]
    5. </a>

    Between each part of those strings you will have to use the + operator

    Code:
    rl.innerHTML='<a href="' + addr[ri] + '">' + addr[ri] + '</a>';

  • Users who have thanked devnull69 for this post:

    joliett89 (10-08-2011)

  • #3
    Regular Coder
    Join Date
    Jul 2011
    Posts
    172
    Thanks
    64
    Thanked 2 Times in 2 Posts
    Thanks, this is working now...

  • #4
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Escape characters are part of the syntax for many programming languages, data formats and communication protocols. For a given alphabet an escape character's purpose is to start character sequences (so named escape sequences) which have to be interpreted differently from the same characters occurring alone. An escape character may not have its own meaning, so all escape sequences are of 2 or more characters.
    There are usually two functions of escape sequences. The first is to encode a syntactic entity, such as device commands or special data which cannot be directly represented by the alphabet. The second use, referred to as character quoting, is to represent characters which cannot be typed in current context, or would have an undesired interpretation. In the latter case an escape sequence is a digraph consisting of an escape character itself and a "quoted" character.
    Last edited by venegal; 10-08-2011 at 05:36 PM. Reason: signature rule violation


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •