By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,140 Members | 1,265 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,140 IT Pros & Developers. It's quick & easy.

How to prevent a form submission without an attachment?

P: 127
need to validate before the form submit, whether the user selected the file for upload...

without file attachment the form shouldn't be submitted. it will show a message to the user "please a select file to upload'...

how to do it with javascript??

its my form...

Expand|Select|Wrap|Line Numbers
  1. <form method="POST" name="email" action="sendmail.php" enctype="multipart/form-data" onSubmit="return validateForm()";>
  3.     <table border=0 cellPadding=5 cellSpacing=10 width=100%>
  5.         <tr>
  6.             <td><label for='name'>Name:</label></td>
  7.             <td><input  type="text" name="name"  maxlength="50" size="30" ononkeyup="AllowAlphabet()"></td>
  8.         </tr>
  9.          <tr>
  10.             <td><label for='familyname'>Family Name:</label></td>
  11.             <td><input  type="text" name="fname" maxlength="50" size="30"></td>
  12.         </tr>
  13.          <tr>
  14.             <td><label for='age'>Age:</label></td>
  15.             <td><input  type="number" name="age" maxlength="50" size="30"></td>
  16.         </tr>
  17.         <tr>
  18.             <td><label for='experience'>Years of Experience:</label></td>
  19.             <td><input  type="number" name="exp" maxlength="50" size="30"></td>
  20.         </tr>
  21.         <tr>
  22.             <td><label for='university'>University Attened:</label></td>
  23.             <td><input  type="text" name="university" maxlength="50" size="30"></td>
  24.         </tr>
  25.          <tr>
  26.             <td><label for='phone'>Phone Number:</label></td>
  27.             <td><input  type="text" name="phone" maxlength="50" size="30"></td>
  28.         </tr>
  29.          <tr>
  30.             <td><label for='email'>Email:</label></td>
  31.             <td><input  type="email" name="email" maxlength="50" size="30"></td>
  32.         </tr>
  33.         <tr>
  34.             <td><label for='resume'>Resume:</label></td>
  35.             <td><input type="file" name="resume"></td>
  36.         </tr>
  37.         <tr>
  38.             <td colSpan=2 align=center><input class=subbtn type="submit" value="Submit" name='submit' /></td>
  39.         </tr>
  41.     </table>
  42. </form>
Dec 27 '13 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 8,639
just check, if the appropriate input field is empty (has an empty value).
Dec 27 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.