www.webdeveloper.com
Results 1 to 4 of 4

Thread: JS description in quotation marks

  1. #1
    Join Date
    Mar 2011
    Posts
    3

    JS description in quotation marks

    Hi,

    i am not so good in Eanglish.

    I have a problem with text in quotation marks

    syntax
    1. Is good:
    alert("Hi, my name Tom");

    2. Is bad:
    alert("Hi,
    my name Tom");

    I get text from database ant put it in JS. But when i get text like 2. example, all JS break.

    http://www.kiberdzinas.lt/tadas/pameciau/test2.php

  2. #2
    Join Date
    Nov 2002
    Location
    Flint, Michigan, USA
    Posts
    593
    Your second version contains a carriage-return (character 13) or new-line (character 10) at the bad spot. How to fix it depends on how it came to be there and how it arrives somewhere that you can fix it. Can you post the code that produces the problem?
    Please give me a hand at http://www.gofundme.com/bkzr98.

  3. #3
    Join Date
    Mar 2011
    Posts
    3
    =========================== To database ============================
    <textarea name="tekstas" id="tekstas" onKeyUp="paspausti()" ></textarea>
    <input type="submit" name="submit" value="Skelbti"/>

    ---------------------------------------------------------------------------------
    $tekstas = $_POST["tekstas"];
    $tekstas = htmlspecialchars($tekstas, ENT_QUOTES);

    mysql_query("INSERT INTO tado_taskas_test (aprasymas, lat, lng) VALUES('$tekstas','2','1')");
    ==================================================================

    ========================= From database =============================

    <script type="text/javascript">
    //<![CDATA[

    // this variable will collect the html which will eventually be placed in the side_bar
    var side_bar_html = "";
    var lastlinkid;

    // A function to create the marker and set up the event window
    function aprasymas(name) {
    // add a line to the side_bar html
    side_bar_html += '<div id="ID_kazkoks"><div class="js_spalva" >' + name + '</div></div>';
    }
    <?php
    $i = 0;
    $kordinate = mysql_query("SELECT aprasymas FROM tado_taskas_test");
    while ($row = mysql_fetch_array($kordinate)) {
    $apr[$i] = $row['aprasymas'];
    $i++;
    }
    $j = 0;
    while ($j < $i) {
    echo 'html = "' . $apr[$j] . '";' . "\n";
    echo 'aprasymas(html);'. "\n \n";
    $j++;
    }
    ?>

    // put the assembled side_bar_html contents into the side_bar div
    document.getElementById("side_bar").innerHTML = side_bar_html;

    </script>

  4. #4
    Join Date
    Mar 2011
    Posts
    3
    I found solution

    $j = 0;
    while ($j < $i) {
    $text = str_replace(Array("\r","\n"),Array('<br>'),$apr[$j]);
    echo 'html = "' . $text . '";' . "\n";
    echo 'aprasymas(html);'. "\n \n";
    $j++;
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles