function validateForm() { //text validation if (document.forms[0].fname.value == '') { alert('First name is required.'); return false; } //check length of text value if (document.forms[0].fname.value.length < 2 || document.forms[0].fname.value.length > 20) { alert('First name should be 2-20 characters.'); return false; } //text validation if (document.forms[0].sname.value == '') { alert('Last name is required.'); return false; } //selection list validation if (document.forms[0].city.value == 'Select city') { alert('Select a city.'); return false; } if (confirm('Do you want to continue?')) { set return true; } else return false; }