I want the cursor to be in a particular textbox when the page loads. I achieved it using document.formname.formname.focus()
But the textbox has a default text. And i want it to disappear once the user starts typing. how can i get rid of this default test ?

Recommended Answers

All 2 Replies

Add this code to the head of your document (Or in an external file if you use one)

<script type="text/JavaScript">
function checkValue() {
  if(document.getElementById('my_field').value == "default_value") {
    document.getElementById('my_field').value = "";
  }
}
</script>

Change my_field and default_value to the relevant values for your script.

Then add an onkeypress event to your input field for the function.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.