View Full Version : clear form script complications

06-20-2008, 04:26 PM
Hi I have the following javascript

function ClearValue(myForm,myField){
if(document.searchform2.query2.value == document.searchform2.query2.defaultValue){
document.searchform2.query2.value = "";

and calling to that I have...

<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

06-20-2008, 06:08 PM
Have a look at http://www.codingforums.com/showthread.php?t=131094 !