HTML encode for JavaScript

Discussion in 'JavaScript' started by kuser, Dec 29, 2012.

  1. #1
    Ok, If i wish to copy the content from DIVA in DIVB i can easy do it with something like

    document.getElementById('divb').innerHTML = document.getEmenetById('diva').innerHTML;

    Now i have another problem ... the content from DIVA is saved in a PHP file, and i wish to autoload it if possible! how the heck in the world i can do it?! because some codes may have " / ' .... like <b></b> <font color="red"> ,<a href="" onClick=''>...
     
    kuser, Dec 29, 2012 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #2
    I'm not entirely clear what you are asking -- but it sounds like you are doing things in JavaScript client-side that have no business being done in JavaScript client-side. Sounds more like a job for server-side since you're talking about manipulating content.

    NOT that you have any business using tags like FONT or attributes like COLOR any time after 1997 :p
     
    deathshadow, Dec 30, 2012 IP
  3. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #3
    If you're talking about doing this after the user has done something to change the contents of DivA, it can't be done directly in PHP, since the PHP code no longer exists at that time. (If you don't know how the client-server model works, learn.) You could do it using AJAX. How you do it, though, depends on exactly where the innerHTML of DivA is being generated.

    If you're talking about doing this before sending the HTML and JS to the client, just write DivB using the content of DivA:

    <?php
    echo '<div id="b">blah blah</div>';
    ?>

    where "blah blah" is the contents of DivA.
     
    Rukbat, Dec 30, 2012 IP