Results 1 to 6 of 6

Thread: postComment.php?text=&quote;hello...&quote; will make result empty on variable text.

  1. #1
    Join Date
    Aug 2008
    Location
    karanganyar, solo, indonesia
    Posts
    161
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Arrow postComment.php?text=&quote;hello...&quote; will make result empty on variable text.



    hello....
    i'm making post comment for my user using this method

    postComment.php?targetID=11&yourTextComment=text
    for the "text", i use document.getElementById('mytextareaID').value;

    this method is good thing if user just input text, not html.
    unfortunately, my textarea is modificated to integrated with WYSIWYG editot, of course in here the value of my textarea id is HTML text.

    my problem is ,
    if my user type like "hello..." on my textarea, of course the textarea value will be &quote;hello...&quote; ( as what i said before, it integrated with WYSIWYG editor)

    so if my url
    postComment.php?targetID=11&text=&quote;hello...&quote; it will say that my text value is empty.

    CAN ANYONE HERE HELP ME?
    thanks
    ///////////////////////////////////////////////////
    ///// http://www.mediatutorial.web.id
    ///////////////////////////////////////////////////

  2. #2
    Join Date
    Aug 2008
    Location
    karanganyar, solo, indonesia
    Posts
    161
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    i try by using "&text=encodeURIComponent(textvalue)"
    but nothing fix
    ///////////////////////////////////////////////////
    ///// http://www.mediatutorial.web.id
    ///////////////////////////////////////////////////

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,167
    Thanks
    44
    Thanked 3,240 Times in 3,201 Posts
    Blog Entries
    12

    Default

    This will never work:

    Code:
    "&text=encodeURIComponent(textvalue)"
    We may need to see the code. What you've posted so far is very confusing.

    But, yes the solution is to encodeURIComponent() the value of the textarea before appending it to the URL. It would be something like so:

    Code:
    var URL = 'postComment.php?targetID=11&yourTextComment=';
    URL += encodeURIComponent(document.getElementById('mytextareaID').value);
    window.open(URL);
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Aug 2008
    Location
    karanganyar, solo, indonesia
    Posts
    161
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Arrow hello...

    well, my site here using 2 files.
    *postComment.html
    *commentProcess.php

    below is a very simple code that i use:
    *postComment.html
    <html>
    <head><title> post comment</title>

    <script type="text/javascript">

    function submit_comment(){
    var text=document.getElementById('comment_text').value;
    if(text==""){alert('Please fill in the text');return false;}
    //do ajax
    var comment_ajax=createAjaxObj();//this function is on another file
    var url= 'commentProcess.php?targetID=11&yourTextComment='+encodeURIComponent(text);
    url +="&r="+Math.random();
    //procesing ajax
    comment_ajax.open('GET",url);
    comment_ajax.onreadystatechange=function(){
    if(comment_ajax.readyState==4 && comment_ajax.status==200){
    document.getElementById('comment_result').innerHTML=comment_ajax.responseText;
    }
    }
    comment_ajax.send(null);
    }

    </script>

    </head>
    <body>
    post your comment<br>
    <textarea id="comment_text"></textarea>
    <input type="button" value="submit" onclick="submit_comment();"><br>
    <div id="comment_result"></div>
    </body>
    </html>

    really simple

    then the commentProcess.php ie below:

    <?php
    //commentProcess.php?targetID=11&yourTextComment=hello..mytext..is ..here
    $target_id=$_REQUEST['targetID'];
    $text=$_REQUEST['yourTextComment'];

    if($text==""){
    echo "Please fill in the text comment";
    exit();
    }

    else process_comment();

    ?>

    really super simple! he he

    THE RESULT OF MY PROCESING IS ALWAYS "Please fill in the text comment"

    CAN ANYONE HERE HELP!!!??/
    ///////////////////////////////////////////////////
    ///// http://www.mediatutorial.web.id
    ///////////////////////////////////////////////////

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,167
    Thanks
    44
    Thanked 3,240 Times in 3,201 Posts
    Blog Entries
    12

    Default

    There could be other problems, but:

    Code:
    comment_ajax.open('GET",url);
    Shouldn't be working at all, and if it is, shouldn't be passing anything to any page.

    Please post a link to the page on your site that contains the problematic code so we can check it out.
    Last edited by jscheuer1; 12-29-2008 at 03:32 PM.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Aug 2008
    Location
    karanganyar, solo, indonesia
    Posts
    161
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default hello...

    hello....
    it has worked....
    my problem solved!
    ///////////////////////////////////////////////////
    ///// http://www.mediatutorial.web.id
    ///////////////////////////////////////////////////

Bookmarks

Posting Permissions

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