I hope this hasn't been discussed before. I searched but couldn't find a thread for this.
I have an input (type="text") with some default text telling the user to enter something in the box. The input tag includes an onmousedown event which runs javascript function to clear the default text so the user can start entering their own text.
This setup behaves in two possible ways, one is good and one is bad:
Good: If the user clicks inside the text box, but after the default text, the text gets cleared and the cursor shows up at the beginning of the text box.
Bad: If the user clicks inside the text box, but directly on the default text, the text gets cleared, but the cursor is not displayed and the text box does not have the focus. In order to start typing, the user must click on the text box again.
So my question is: If the cursor is inside a string of text which gets cleared, is there a way to reinstate the cursor and the text box focus?
Here is simplified version of code involved:
<script type="text/javascript">
function startcomment(commentid){
document.getElementById(commentid).value = "";
}
</script>
<input id="cid" type="text" value="Start a conversation about this" onmousedown="startcomment('cid')"></input>