Web Analytics Made Easy -
StatCounter Keeping Paragraphs using TextArea with AJAX - CodingForum

Announcement

Collapse
No announcement yet.

Keeping Paragraphs using TextArea with AJAX

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

  • Keeping Paragraphs using TextArea with AJAX

    Hi guys,

    I cant seem to work out a way to keep my paragraphs when using a text area as part of a form.

    I send the form using ajax and then display the text again in a textarea to allow editing before finally displaying it on a standard page.

    This is the form I am currently using:

    Code:
    <form action="javascript:insertChunk()" method="post" >
    <h3>Chunk Name<br />
    <input type="text" id="txtChunkTitle" name="txtChunkTitle" length="42"/></h3>
    						
    <h3>Chunk Description<br />
    <textarea type="text" name="txtChunkContent" id="txtChunkContent" cols="30" rows="15"></textarea></h3>
    						
    <div id="addChunkBut">
    <input type="button" name="submit" value="Click To Create Chunk" onclick="insertChunk()" />
    </div>
    </form>
    I do nothing special to the input after:
    Code:
    var chunkTitle= document.getElementById('txtChunkTitle');
    var chunkContent = document.getElementById('txtChunkContent');
    params = "?chunkTitle=" + chunkTitle.value + "&chunkContent=" + chunkContent.value;
    Then pass it through ajax to php file
    Code:
    $chunkTitle = $_GET['chunkTitle'];
    $chunkContent = $_GET['chunkContent'];
    I then store that into the database using a standard insert into sql statement.


    I have tried playing around with various things i have seen on the net but to no avail so thought id show the base form and see if someone knows how to do this or if its possible.

    Thanks

  • #2
    When your displaying it on the screen. Have you looked at the source to see if the paragraphs are there. You could always do a str_replace to replace the line breaks with html <br />.
    You can not say you know how to do something, until you can teach it to someone else.

    Comment


    • #3
      Originally posted by timgolding View Post
      When your displaying it on the screen. Have you looked at the source to see if the paragraphs are there. You could always do a str_replace to replace the line breaks with html <br />.
      Well when I look at the content in the db using phpMyAdmin then it just shows as a line - which I assume means that is how the data is held.

      Comment


      • #4
        Ah i get it because you are passing it through with AJAX as GET, perhaps you have to urlencode it first before passing it through get
        You can not say you know how to do something, until you can teach it to someone else.

        Comment


        • #5
          Not sure how to do that with Javascript. Here's an article i found -> http://cass-hacks.com/articles/code/...encode_decode/. Then you just use urldecode before writing it to the database.
          You can not say you know how to do something, until you can teach it to someone else.

          Comment


          • #6
            Originally posted by timgolding View Post
            Not sure how to do that with Javascript. Here's an article i found -> http://cass-hacks.com/articles/code/...encode_decode/. Then you just use urldecode before writing it to the database.
            Thanks will have a look through and see if it can help.

            Comment


            • #7
              Using escape() i now have the data into the database correctly.
              Last edited by Vanq69; Apr 14, 2009, 05:27 AM.

              Comment

              Working...
              X