Javascript – checking text field value length


I am trying to see if the text field length is at least a certain length. here is my code:

<form name="form2" id="form2" onsubmit="return validate()">
length 4: <input type="text" name = "t" id="t" />
<input type="button" name="submit" value="submit" />

function validate() {
    submitFlag = true;
        alert("ivalid length - 4 characters needed!");
    return submitFlag;

when I click submit, nothing happens.

Best Solution

Change your submit button to type="submit". The form is never getting submitted so the validate function isn't being called.