I am trying to create a textbox watermark using javascript but with the current code I get a error
Webpage error details
Message: ‘searchInput’ is undefined
<script type="text/javascript" language="javascript">
function watermark(inputId,text){
var inputBox = document.getElementById(searchInput);
if (inputBox.value.length > 0){
if (inputBox.value == text)
inputBox.value = '';
}
else
inputBox.value = text;
}
</script>
<input name="keyword2" id="searchInput" type="text" class="searchbox2"
value="Enter a State, County, City or Zip" size="77" maxlength="30"
onfocus="watermark('searchInput','Enter a State, County, City or Zip');"
onblur="watermark('searchInput','Enter a State, County, City or Zip');"/>
Add quotes around searchInput.
getElementById accepts a string, you are referencing an undeclared variable.