I am not a professional programmer and try to do some light coding. I created the form below doing some research in the web but I can't prepare JavaScript validation scripts so that user can't keep any field blank. I didn't even declare any ID for the form. Please come up with something so that I can proceed. <form action="upload_results.php" enctype="multipart/form-data" method="post"> <table align="center" bgcolor="#CCCCCC" width="250px"> <tr> <td align="left"><b>Exam Name:</b></td> </tr> <tr> <td align="left"> <select name="ex_id"> <?php foreach($exam_ary as $key=>$value) { echo "<option value='$key'>$value</option>"; } ?> </select> </td> </tr> <tr> <td align="left"><b>Date of Exam:</b></td> </tr> <tr> <td align="left"> <?php $myCalendar = new tc_calendar("date5", true, false); $myCalendar->setIcon("calendar/images/iconCalendar.gif"); //$myCalendar->setDate(date('d'), date('m'), date('Y')); $myCalendar->setPath("calendar/"); $myCalendar->setYearInterval(2000, 2015); $myCalendar->dateAllow('2008-05-13', '2014-12-31'); $myCalendar->setDateFormat('j F Y'); //$myCalendar->setHeight(350); //$myCalendar->autoSubmit(true, "form1"); $myCalendar->setAlignment('left', 'bottom'); $myCalendar->writeScript(); ?> </td> </tr> <tr> <td align="left"><b>Result File:</b></td> </tr> <tr> <td align="left"> <input type="file" name="result_file"> </td> </tr> <tr> <td colspan="2" align="justify"> [You must upload either a <b>.xls (Microsoft Excel 2003)</b> or a <b>.pdf (Portable Document Format)</b> file] </td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" name="add" value="Upload"> </td> </tr> </table> </form> Code (markup):
You can try something like function checkEmptyInput() { inputArray = document.getElementsByTagName("input"); for (var index = 0; index < inputArray.length; index++) { if (inputArray[index].type = 'text') { if (inputArray[index].value == "") { alert( "Please fill all the fields." ); inputArray[index].focus; return false ; } } } } Code (markup): This will check if all the text fields are non-empty, otherwise throws an alert message.