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 9 of 9
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Echo function not working with Javascript text area

    Hi all!

    I've got a text area that uses Javascript to control the length of the user input to 255 characters.

    The value of that text area is stored in a session variable so that the user can go back to that page to review their input.

    However, when the user returns to the page, the text areas are empty.

    Could anyone please tell me where I've gone wrong?

    Here's the Javascript code:

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    function textCounter(field, countfield, maxlimit) {
    if (field.value.length > maxlimit) 
    field.value = field.value.substring(0, maxlimit);
    else 
    countfield.value = maxlimit - field.value.length;
    }
    </script>
    and here's the HTML and PHP for my text area:

    PHP Code:
           <textarea name="positive" cols="80" rows="3" id="positive" VALUE="<?PHP echo $_SESSION['answer']['positive'];?>" onKeyDown="textCounter(this.form.positive,this.form.remLen,255);" onKeyUp="textCounter(this.form.positive,this.form.remLen,255);"></textarea>
            <input readonly type=text name="remLen" size="3" maxlength="3" value="255">
    Thanks a lot in advance for your help!

  • #2
    Senior Coder koyama's Avatar
    Join Date
    Dec 2006
    Location
    Copenhagen, Denmark
    Posts
    1,246
    Thanks
    1
    Thanked 5 Times in 5 Posts
    You are using the <textarea> element incorrectly. There is no value attribute. Example:
    Code:
    <textarea rows="10" cols="80">Text goes in here</textarea>

  • #3
    New Coder
    Join Date
    Jan 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hmmm... i see.

    So does that mean that users cannot view what they typed in the text areas? Or is there another way to get around that?
    Last edited by Sherrie; 01-08-2007 at 02:20 PM.

  • #4
    Senior Coder koyama's Avatar
    Join Date
    Dec 2006
    Location
    Copenhagen, Denmark
    Posts
    1,246
    Thanks
    1
    Thanked 5 Times in 5 Posts
    Like this:
    PHP Code:
    <textarea rows="10" cols="80"><?php echo $_SESSION['answer']['positive'];?></textarea>

  • #5
    New Coder
    Join Date
    Jan 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    koyama,

    Thanks a lot! That works! Really appreciate it!

    I've run into another problem though,

    If the session variable has a ' in it, it's displaying in the text area as \'

    How do I get around this?

    eg.

    $_SESSION['answer']['improvements']="Let's try this!";

    it's displaying as Let\'s try this!

    Thanks again!

  • #6
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    PHP Code:
    $_SESSION['answer']['improvements']="Let's try this!"
    Try

    PHP Code:
    $_SESSION['answer']['improvements']="Let\'s try this!"
    Escape the ' with a backslash. I'm not sure if it will work though.
    Leonard Whistler

  • #7
    New Coder
    Join Date
    Jan 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Len Whistler,

    Thanks for your quick reply!

    The problem is, that the session variable is stored in the value from a form.

    Would there be a way to compare the patterns and replace all \' with ' If there is, how would I do that?

    Thanks a bunch!

  • #8
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    You probably have magic_quotes on.
    You can remove the "\"'s with stripslashes().
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #9
    New Coder
    Join Date
    Jan 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    marek_mar

    Thanks for your reply! That worked beautifully!

    Greatly appreciate all the help!


  •  

    Posting Permissions

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