Advertisement

07.04.2005 at 08:23PM PDT, ID: 21480086
[x]
Attachment Details

validation problem

Asked by laiyede in JavaScript

Tags: , ,

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>Start Free Trial
 
Loading Advertisement...
 
[+][-]07.04.2005 at 08:30PM PDT, ID: 14365668

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.04.2005 at 08:40PM PDT, ID: 14365698

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.05.2005 at 02:33AM PDT, ID: 14367093

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: JavaScript
Tags: javascript, validation, file
Sign Up Now!
Solution Provided By: mplungjan
Participating Experts: 3
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32