Reputation: 221
I am trying to run a check on all of my text fields using Javascript. I have looked at several examples here and other places to figure out what I am missing. I just can't get out of the weeds.
function validate(form){
var textFieldsReq = document.getElementsByName('textFieldReq');
for(i=0,n=textFieldsReq.length;i<n;i++){
if ( !textFieldsReq.value ){
alert ( 'You need to fill in ' + textFieldsReq[i] + '!');
textFieldsReq.focus();
return false;
}
}
return true;
};
Your direction would be greatly appreciated.
Upvotes: 1
Views: 59
Reputation:
HTML does this job for you! You can use required in the <input>
tag:
<input type="text" required />
Upvotes: 0