validation problem

Hi my validation code below works but I just need to add some code to allow me to check if input box file1 is empty and an message to appear if they try and submit when it is empty. I have tried but when I add some code none of the validation code works. Can anyone help.

Thankyou in advance.


<SCRIPT LANGUAGE="JavaScript">
<!--
function Update()
{
document.forms[0].action = 'welcome.asp?ID=<%= trim( session("ID")) %>';


document.forms[0].submit();

}

// -->
</SCRIPT>


<Script language ="JavaScript">
 // Javascript checks for Registration Form
function submitform(){
 //Enter a FirstName
 if (Register.cvfile.value=="") {
 alert("No file was selected.")
 Register.cvfile.focus();
 return false;  
 
  }
 
 </script>
<Script language ="JavaScript">

extArray = new Array(".doc", ".txt");
function LimitAttach(form, file) {
 
allowSubmit = false;
if (!file) return;
while (file.indexOf("\\") != -1)
file = file.slice(file.indexOf("\\") + 1);
ext = file.slice(file.indexOf(".")).toLowerCase();
for (var i = 0; i < extArray.length; i++) {
if (extArray[i] == ext) { allowSubmit = true; break; }
}
if (allowSubmit) form.submit();
else
alert("Please only upload files that end in types: " 
+ (extArray.join(" ")) + "\nPlease select a new "
+ "file to upload and submit again.");
}

 
</script>

</HEAD>
<body>
<%


<form action="uploaddb.asp" ENCTYPE="MULTIPART/FORM-DATA" method="post">

<table width="731" border="0">
    <tr>
            <th scope="row" colspan="2" align="left">Please Submit Your CV</th>
      </tr>
      <tr>
            <td colspan="2" align="left">Please click the browse button to locate your file on your computer. Then Click "Upload File"</td>
      </tr>
       <tr>

            <td colspan="2" scope="row" height="20"><div align="left">&nbsp;</td>
   </tr>
      <tr>
            <td colspan="2" scope="row"><div align="left"><input type=file name=File1 size="20">
            </div></td>
   </tr><p>
    <tr>
            <td colspan="2" scope="row" height="20"><div align="left">&nbsp;</td>
   </tr>
   <tr>
            <td><input type=button name="Submit" value="Submit" onclick="LimitAttach(this.form,this.form.File1.value)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" name="update" value="New profile" ONCLICK="Update();"></td>
   </tr>
 <tr>
            <td colspan="2" scope="row" height="20"><div align="left">&nbsp;</td>
   </tr>

                  

</table>
                  
</form>
laiyedeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GwynforWebCommented:
If you let us know the complete required validation it might be easier to rewrite the code, it wil not take long. It is a little bit of a muddle at the moment.
sajuksCommented:
//dont know what u r trying to do . i've modified ur code check this
//change the submit button to input type ="submit", called the form validn in the form onsubmit
<SCRIPT LANGUAGE="JavaScript">
<!--
function Update()
{
document.forms[0].action = 'welcome.asp?ID=<%= trim( session("ID")) %>';


document.forms[0].submit();

}

// -->
</SCRIPT>


<Script language ="JavaScript">
 // Javascript checks for Registration Form
function submitform(){
 //Enter a FirstName
 if (Register.cvfile.value=="") {
 alert("No file was selected.")
 Register.cvfile.focus();
 return false;  
 }
  }
 
 </script>
<Script language ="JavaScript">

extArray = new Array(".doc", ".txt");
function LimitAttach(form, file) {

allowSubmit = false;
if (!file)
{
alert("Please Select A File")
form.File1.focus()
return false;
}
while (file.indexOf("\\") != -1)
file = file.slice(file.indexOf("\\") + 1);
ext = file.slice(file.indexOf(".")).toLowerCase();
for (var i = 0; i < extArray.length; i++) {
if (extArray[i] == ext) { allowSubmit = true; break; }
}
if (allowSubmit)
{form.submit();
return true;
}
else
{
alert("Please only upload files that end in types: " 
+ (extArray.join(" ")) + "\nPlease select a new "
+ "file to upload and submit again.");
return false;
}
}

 
</script>

</HEAD>
<body>

<form action="uploaddb.asp" name = "frm" ENCTYPE="MULTIPART/FORM-DATA" method="post" onsubmit="return LimitAttach(document.frm,document.frm.File1.value)">

<table width="731" border="0">
    <tr>
          <th scope="row" colspan="2" align="left">Please Submit Your CV</th>
     </tr>
     <tr>
          <td colspan="2" align="left">Please click the browse button to locate your file on your computer. Then Click "Upload File"</td>
     </tr>
      <tr>

          <td colspan="2" scope="row" height="20"><div align="left">&nbsp;</td>
   </tr>
     <tr>
          <td colspan="2" scope="row"><div align="left"><input type=file name=File1 size="20">
          </div></td>
   </tr><p>
    <tr>
          <td colspan="2" scope="row" height="20"><div align="left">&nbsp;</td>
   </tr>
   <tr>
          <td><input type=submit name="Submit" value="Submit" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" name="update" value="New profile" ONCLICK="Update();"></td>
   </tr>
 <tr>
          <td colspan="2" scope="row" height="20"><div align="left">&nbsp;</td>
   </tr>

               

</table>
               
</form>
Michel PlungjanIT ExpertCommented:
<script language ="JavaScript">
<!--
function Update() {
  location = 'welcome.asp?ID=<%= trim( session("ID")) %>';
}

extArray = new Array(".doc", ".txt");
function LimitAttach(theForm, file) {
  if (!file) {
    alert("Please Select A File")
    theForm.File1.focus()
    return false;
  }
  while (file.indexOf("\\") != -1)
  file = file.slice(file.indexOf("\\") + 1);
  ext = file.slice(file.indexOf(".")).toLowerCase();
  for (var i = 0; i < extArray.length; i++) {
    if (extArray[i] == ext) { return true }
  }
  alert("Please only upload files that end in types: "
  + (extArray.join(" ")) + "\nPlease select a new "
  + "file to upload and submit again.");
  return false;
}

// -->
</script>


<form ..... onsubmit="return LimitAttach(this,this.File1.value)">

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.