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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    clear form script complications

    Hi I have the following javascript
    Code:
    function ClearValue(myForm,myField){
    	if(document.searchform2.query2.value == document.searchform2.query2.defaultValue){
    	document.searchform2.query2.value = "";
    	}	
    }
    and calling to that I have...
    Code:
    <input type="text" name="query2" id="query2" size="15em"  maxlength="100" class="FormTextSmall" value="Search" onFocus="ClearValue('searchform2','query2')" />
    Ok so far so good, but my problem is I want to use the variables set in the html ('searchform2','query2') in the javascript and I'm not sure how. I figured getElementById would work, but apparently I can't figure out how to do so.
    If I enter document.myForm.myField.value = "" then it does nothing... oh, all of this is in an external Javascript file as well. I'd like to not have to create a different javascript function for every form on the website, but just be able to send the name of the form and input to the javascript function and have it use that to clear the value of the input.
    I hope this makes sense, and I'm new at this, so forgive me if there is a simple explanation. Thanks

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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