Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9249101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:06:30+00:00 2026-06-18T10:06:30+00:00

This is my first time working with jQuery and I’m having some difficulty understanding

  • 0

This is my first time working with jQuery and I’m having some difficulty understanding how to implement it on my website, even though its a relatively easy task I am trying to accomplish.

My goal is to modify an existing textarea on my website so that it has a default message displayed that disappears when the client clicks on the textarea to enter his information. Originally I just wanted to use the html placeholder attribute, but for some reason it does not work.. (I am using IE 8). So now I am trying to use this jQuery code which was suggested to me.

Here is the code:

                    <textarea style="background: #F6E3CE; overflow:auto;" rows="3" cols="70" name="sComments" id="sComments" 
                        <script type="text/javascript"><?php
                        $("input#text").focus(function(){
                            if( $(this).val() == "default message" )
                            {
                                $(this).val("");
                            }
                        }).blur(function(){
                            if( $(this).val() == "" )
                            {
                                $(this).val("default message");
                            }
                        }); ?>
                        </script>
                        onchange="commentsChanged(this,<?php echo $pKey;?>);"><?php echo str_replace('\r\n', "\n", rtrim($variable1[0][aComments]));?></textarea>

If I understand correctly, I referenced the jQuery file at the beginning of my code as such:

<script language="JavaScript" src="../js/jquery-1.6.4.js"></script>

On this latest attempt, this part of the website would not even open. After doing some research I am still unsure what I am doing wrong.

Thank you.

EDIT: Both answers below are excellent and work great. Tenhouse’s is more “proper” because it seperates logic and formatting, but Chandrakant’s use of inline JavaScript works equally as well and is actually what I used on my website.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:06:31+00:00Added an answer on June 18, 2026 at 10:06 am

    First off you are mixing up PHP code with JavaScript code which will not work, since they are in no direct relation.

    Secondly you have to put your focus / blur -listeners in the document ready function (this means it will load when the document is loaded).

    Thirdly I highly recommend to read some about the basics of jQuery – you could start with this:
    http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery

    Edit: Since you really seem to be very confused about everything, here a full example:

    <html>
        <head>
            <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
            <script type="text/javascript">
                $(document).ready(function() {
                    var defaultMessage = "default message";
                    $("#myTextArea").focus(function(){
                        if( $(this).val() == defaultMessage){
                            $(this).val("");
                        }
                    }).blur(function(){
                        if( $(this).val() == "" ){
                            $(this).val(defaultMessage);
                        }
                    }).val(defaultMessage);
                });
            </script>
        </head>
        <body>
            <textarea id="myTextArea"></textarea>
        </body>
    </html>
    

    In the example above you can also see that I use a newer jQuery-Version – directly from their servers.

    Viewing the other answer of Chandrakant:

    I don’t agree putting the JavaScript part directly into the element. It’s not a good practice, since you should always try to split logic & formatting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on this website and have implemented JQuery's animate() for the first time
This is my first time attempting working with JQuery, Json AND calling a web
I'm working with jQuery Mobile for the first time and I'm having trouble accomplishing
This is my first time working with a WPF datagrid. From what I understand
This is my first time working with file i/o in java, and it's not
this is my first time asking a question on stackoverflow. I'm working on a
This is the first time I am working for a front-end project that requires
Working with jquery.ajax for first time... I have a class in C#: public class
this is my first time using jquery, and i dont think it seems to
This is the first time I've ever tried JQuery basically because I couldnt get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.