validate form data using javascript to check required html elements

for use in a javascript function to submit a form

var form = document.getElementById('myForm');
for(var i=0; i < form.elements.length; i++){
  if(form.elements[i].value === '' && form.elements[i].hasAttribute('required')){
    alert('Fields marked with * are Required.');
    return false;


Other Items in js
Page Views

This page has been viewed 45 times.

Search Code
Search Code by entering your search text above.

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.