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 4 of 4

Thread: form clearing

  1. #1
    New Coder
    Join Date
    Dec 2003
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    form clearing

    The function clear_text() is called when a user clicks on a text box in my form so that the default value (Type text here) is removed so that only what the user types in in the text box. I can clear it by refering to it specifically, document.form_name.textbox_name.value = ""; to call this I used the onClick="clear_text()" event when a user clicks on the text box. HOWEVER, I am using more then 1 text box and I wish to use the same function for all text box's. So I made it like: onClick="clear_text(this.name)" and the function:

    function clear_text(name)
    {
    document.email(the name of the form).name.value = "";
    }


    this passes the right variable, it passes the name of the form elementcorreclty and there are no errors but the script still doesnt work. Why is this and how do I fix it? Or must I continue to refer to each text box seperately in this situation?
    Spiral Out

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    this should do it:


    onClick="clear_text(this);"


    function clear_text(aObj)
    {
    aObj.value = "";
    }

  • #3
    New Coder
    Join Date
    Dec 2003
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Cheers, thanx dude.
    Spiral Out

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,966
    Thanks
    0
    Thanked 236 Times in 233 Posts

    shorter code

    why not just use this?

    <input onfocus="this.value=''" ...>


  •  

    Posting Permissions

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