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 9077147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:16:24+00:00 2026-06-16T19:16:24+00:00

I really don’t understand why this is being so hard for me to get

  • 0

I really don’t understand why this is being so hard for me to get working:

  • http://jsfiddle.net/jp2code/qCExy/

It will eventually be going into an ASP.NET control, so I believe I need to pass Javascript the <textarea> control’s ID.

It doesn’t work.

So, in the jsFiddle, I tried using standard controls for First and Last names, but they don’t work either.

EDIT:

I’ve been playing around with the jsFiddle, and it appears that my jsOnFocus is never called (alert never fires). However, I was able to run down a little script from someone else that makes the multiline textbox clear and reset – I just can’t seem to find a way to call this from a javascript function:

  function jsOnFocus(obj) {
      alert("Inside the jsOnFocus.");
      if (obj.Value==obj.defaultValue)
          obj.Value="";
  }
  function jsOnBlur(obj) {
      if (obj.Value==="")
          obj.Value=obj.defaultValue;
  }

​
Here is the HTML.

  <table>
    <tr><td>Message:</td><td>&nbsp;</td></tr>
    <tr>
      <td>&nbsp;</td>
      <td>
        <textarea name="txtMsg" rows="6" cols="30"
          onfocus="if(this.value==this.defaultValue)this.value='';" 
          onblur="if(this.value==='')this.value=this.defaultValue;">[Write your message here or call my voice number at (555) 222-1234.]</textarea>
      </td>
    </tr>
    <tr>
      <td>Test1:</td>
        <td><input type="text" name="txtTest1" 
          onfocus="jsOnFocus(txtTest1)" 
          onblur="jsOnBlur(txtTest1)" value="Test1" /></td>
    </tr>
    <tr>
      <td>Test2:</td>
  <td><input type="text" name="txtTest2" 
          onfocus="if(this.value=='Test2'){this.value=''};" value="Test2" /></td>
    </tr>
    <tr>
      <td>Test3:</td>
        <td><input type="text" name="txtTest3" 
          onfocus="if(this.value==this.defaultValue)this.value='';" 
          onblur="if(this.value==='')this.value=this.defaultValue;" value="Test3" /></td>
    </tr>
  </table>​

“Message” works, but I’d like to get the code to running in a javascript that I can place in my “js” file and use on other objects.

“Test1” is an attempt to call the javascript, but it does not work.

“Test2” works, but it does not use the technique in “Message”.

“Test3” works, and it does use the technique in “Message”.

Does anyone see how to make this code work in the javascript instead of inline html?

jsFiddle Link: http://jsfiddle.net/jp2code/qCExy/10/

  • 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-16T19:16:25+00:00Added an answer on June 16, 2026 at 7:16 pm

    I played around a bit with your fiddle. I’m a newb when it comes to jsfiddle though so I did not dare to try to save my changes.

    Anyway, there are a few things that keep the Test1 box from working. First of all, the script in the “JavaScript” block in the fiddle is added to the page like this (check by viewing source in the Result section):

    <script type='text/javascript'>//<![CDATA[ 
        window.addEvent('load', function() {
            function jsOnFocus(obj) {
                alert("Inside the jsOnFocus.");
                if (obj.Value==obj.defaultValue)
                    obj.Value="";
            }
            function jsOnBlur(obj) {
                if (obj.Value==="")
                    obj.Value=obj.defaultValue;
            }
        });//]]>  
    </script>
    

    So your functions are not in a scope (for lack of a more precise term) where you can call them like you tried to do.

    To fix this I added the script directly in the Html section inside as <script> block.

    There was also a small issue with the javascript code itself. The value property is called value, not Value.

    Also, I changed the onfocus and onblur attributes on the input to pass this to the functions. You can of course change it to pass an id if you want and then look up the control using the id. In that case make sure that the control has an id specified.

    Anyway, here is the resulting code from the Html section of the fiddle:

    <script type="text/jscript">
        function jsOnFocus(obj) {
            if (obj.value==obj.defaultValue)
                obj.value="";
        }
        function jsOnBlur(obj) {
            if (obj.value==="")
                obj.value=obj.defaultValue;
        }
    </script>
    <table>
      <tr><td>Message:</td><td>&nbsp;</td></tr>
      <tr>
        <td>&nbsp;</td>
        <td>
          <textarea name="txtMsg" rows="6" cols="30" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value==='')this.value=this.defaultValue;">[Write your message here or call my voice number at (555) 222-1234.]</textarea>
        </td>
      </tr>
      <tr>
        <td>Test1:</td>
          <td><input type="text" name="txtTest1" onfocus="jsOnFocus(this)" onblur="jsOnBlur(this)" value="Test1" /></td>
      </tr>
      <tr>
        <td>Test2:</td>
          <td><input type="text" name="txtTest2" onfocus="if(this.value=='Test2'){this.value=''};" value="Test2" /></td>
      </tr>
      <tr>
        <td>Test3:</td>
          <td><input type="text" name="txtTest3" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value==='')this.value=this.defaultValue;" value="Test3" /></td>
      </tr>
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I really don't get why this is not working. I want to avoid a
I really don't get why this isn't working, so please help. I'm trying to
I really don't understand how all this flags working since I do exactly what
I really don't understand this. I have a simple ASP with 3 div in
I really don't understand why this function doesn't work: function GetNomRepertoireTemporaire:WideString; var PathLocal :
I really don't think this has anything to do with ASP.NET MVC 2 itself,
I am not being flip I really don't get it. I just read a
i really don't get how I can use a spinner just like asp.net's dropdownlist,
I really don't know, why this is so complex and hard just for reading
I really don't understand Javascript. In PHP, I can remove quotes like this: $tags_array

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.