Some times you might want to set default values for the HTML elements like Textbox and Drop down fields through Javascript. The below script would be very handy for this task.


<SCRIPT type="text/javascript">
//Function to set the default value for the passed object
function setDefaultValue(inputObj)
{
if(inputObj.type == "text")
{
inputObj.value="";
}
else if((inputObj.type).substr(0, 6) == "select")
{
inputObj.selectedIndex=0;
}
}
function $(element)
{
return document.getElementById(element);
}
</SCRIPT>



I've implemented the above function just only for text field and drop down. You can even extend this functionality for other HTML form fields as well. Here is an example - give a try





This program has been tested on all the major browsers like IE >= 6.0, Mozilla >= 2.0 and Google chrome...