+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: Simple onfocus command

  1. #1
    focus is offline x10 Sophmore focus is an unknown quantity at this point
    Join Date
    Feb 2008
    Posts
    112

    Simple onfocus command

    At the moment i have this:

    <textarea name="comment" cols="55" rows="8">Please feel free to leave a comment or a question here</textarea>

    I want it to go blank when the user click on it.


    Can anyone help me with this?

  2. #2
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: Simple onfocus command

    HTML Code:
    <textarea name="comment" cols="55" rows="8" onclick="this.value=''">Please feel free to leave a comment or a question here</textarea>

  3. #3
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Simple onfocus command

    1. Textarea does not have onclick event
    2. If it did, that would clear the area even when a user went back to edit the area

    HTML Code:
    <html>
    <head><title>Test</title>
    <script type="text/javascript">
    var flag = true ;
    function clear_me(){
      if( flag ){
          var t = document.getElementById( 'comm' );
          t.defaultValue  = '' ;
          flag = false;
      }
    }
    </script>
    <body>
    <textarea name="comment" cols="55" rows="8" id="comm" 
    onfocus="clear_me()" ;>Please feel free to leave a comment or a question here</textarea>
    </body>
    </html>

  4. #4
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: Simple onfocus command

    Ha, how could I forget that.
    Last edited by lemon-tree; 05-12-2010 at 10:30 AM.

  5. #5
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Simple onfocus command

    Quote Originally Posted by lemon-tree View Post
    Ha, how could I forget that.
    Not your mistake, mine.
    It does have an onclick event.


    But the part about needing a flag to disable it after the first use is valid. Plus, onfocus works even in the case they use TAB to get to the textarea rather than by clicking.

    Hmmm.....under further testing, using 'defaultValue' seems to remove the need for the flag, while 'value' does require it.
    Last edited by descalzo; 05-12-2010 at 10:46 AM.

  6. #6
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: Simple onfocus command

    Hmmm.....under further testing, using 'defaultValue' seems to remove the need for the flag, while 'value' does require it.
    You mean something like this:
    HTML Code:
    <textarea name="comment" cols="55" rows="8" id="comm" 
    onfocus="if(this.value == this.defaultValue){this.value = ''}">Please feel free to leave a comment or a question here</textarea>
    I have no idea if that works on text areas though.

  7. #7
    focus is offline x10 Sophmore focus is an unknown quantity at this point
    Join Date
    Feb 2008
    Posts
    112

    Re: Simple onfocus command

    Thanks works fine

    I have one other thing, thought I'd ask here instead of making a new thread...


    How do i get the below to work?


    if (document.orderform.terms.value== false) {
    alert("You must agree to our terms and conditions below an order can be processed")
    document.orderform.terms.focus()
    return false
    }

    HTML:
    <p>By clicking on the below you have read and agree to our terms and conditions</p>
    <input type="checkbox" name="terms" /><p>I Agree</p>

  8. #8
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: Simple onfocus command

    You'll want to use the '.checked' term, instead of '.value' to see if a box is checked. You may also have problems with your referencing of the DOM objects.

  9. #9
    focus is offline x10 Sophmore focus is an unknown quantity at this point
    Join Date
    Feb 2008
    Posts
    112

    Re: Simple onfocus command

    I tried the below and it still doesn't work (

    if (document.orderform.terms.checked== false) {
    alert("You must agree to our terms and conditions below an order can be processed")
    return false
    }



    What do you mean by DOM objects?

  10. #10
    as4s1n's Avatar
    as4s1n is offline x10 Sophmore as4s1n is an unknown quantity at this point
    Join Date
    Apr 2009
    Location
    Washington State
    Posts
    174

    Re: Simple onfocus command

    try:
    Code:
    var checkBox = document.forms.orderForm.elements.terms;
    if(checkBox.checked == false) {
        // Run code
    }
    Last edited by as4s1n; 05-13-2010 at 11:33 AM.
    There is no such thing as a "stupid question," there are only "stupid people" who don't ask them.

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Galactic Command
    By psgalaxy91 in forum Graphics & Webdesign
    Replies: 4
    Last Post: 04-15-2010, 04:32 PM
  2. SQL Command Line
    By gavicus in forum Programming Help
    Replies: 3
    Last Post: 07-04-2009, 12:00 PM
  3. PHP command creation help
    By leafypiggy in forum Programming Help
    Replies: 4
    Last Post: 06-14-2008, 06:27 PM
  4. Command line?
    By shaiaqua in forum Free Hosting
    Replies: 2
    Last Post: 05-09-2008, 10:10 PM
  5. log into sql from command line?
    By chess314 in forum Scripts & 3rd Party Apps
    Replies: 6
    Last Post: 01-30-2008, 03:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers