my textbox and the function in javascript
Soon after the textbox loses the focus the error message should be displayed and the focus has to be set back to the textbox. Likewise i'm doing for different txtbox on various condition.
Here the error message is displayed but the focus is not set to the textbox again moving to the textbox which I clicked. It should not allow me to move to the next field rather it should display the error message and focus on the same textbox.
Help me.
Thanks,
vigneshwarie.
Code:
<td><input type="text" name="username" id="username" onblur="validate('text','username','user')">
<div id="user"></div></td>
<script type="javascript">
function validate(type,fieldname,divid)
{
var txt_value=document.getElementById(fieldname).value;
if(type=='text')
{
if(txt_value==""||txt_value==null)
{
document.getElementById(divid).innerHTML="<span style='color:red;'>Mandatory!</span>"
document.getElementById(fieldname).focus();
return false;
}
}
}
</script>
Here the error message is displayed but the focus is not set to the textbox again moving to the textbox which I clicked. It should not allow me to move to the next field rather it should display the error message and focus on the same textbox.
Help me.
Thanks,
vigneshwarie.
Comment