You are going a long way round.
var
kks=user.value.length
if (kks==0)
First of all, to assign the meaningless name kks to the length of the variable user is plain silly. Always assign meaningful names/ids. Such as uservaluelen. Likewise assigning an id of abcd for the textbox is also plain daft.
But there is no point in having an extra function - all you need is
Code:
<script type = "text/javascript">
function validate() {
document.getElementById('message').innerHTML = ""; // reset
var user = document.getElementById('username').value;
if (user.length) == 0 {
document.getElementById('message').innerHTML = "You must enter your name";
// re-focus on the input field
return false;
}
}
</script>
Secondly, form validation of the pattern if (document.formname.formfield.value == "") (or length ==0) - that is blank - is barely worthy of the name, and virtually useless, as even a single space, an X or a ? will return false, that is pass the validation. A proper name may only contain letters, hyphen, space and apostrophe.
Numeric values, such as zip codes, phone numbers and dates, should be validated as such. Ditto email addresses.
This topic has been covered many times before in this forum.
And Franco di Santo, who never scored here in his spell with Chelsea, threatened to do the same for the opposition. - Commentator BBC 1