Click to See Complete Forum and Search --> : Form Validation & File Upload Validation


instantnet11
08-04-2003, 06:32 PM
Hello,

I am trying to combine 2 Javascripts together and it seems they are both fighting it out One is a form field validation and the other is a file type upload validation. They both work separately. I was wondering is there also a way to make them both part of the from submit rather that on both different calls? I would also like the upload form to be blank if needbe.


<HEAD>
<!-- FILETYPE UPLOAD VALIDATION START-->
<SCRIPT LANGUAGE="JavaScript">


<!-- Begin
extArray = new Array(".gif", ".jpg", ".png", ".jpeg", ".pjpeg" );
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.");
}
// End -->
</script>
<!-- FILETYPE UPLOAD VALIDATION END-->

<!-- TEXTBOX VALIDATION START-->

<script LANGUAGE=JAVASCRIPT TYPE="text/javascript" >

<!--


function _CF_onError(form_object, input_object, object_value, error_message)
{
alert(error_message);
return false;
}



function _CF_hasValue(obj, obj_type)
{
if (obj_type == "TEXT" || obj_type == "PASSWORD")
{
if (obj.value.length == 0)
return false;
else
return true;
}
else if (obj_type == "SELECT")
{
for (i=0; i < obj.length; i++)
{
if (obj.options[i].selected)
return true;
}

return false;
}
else if (obj_type == "SINGLE_VALUE_RADIO" || obj_type == "SINGLE_VALUE_CHECKBOX")
{

if (obj.checked)
return true;
else
return false;
}
else if (obj_type == "RADIO" || obj_type == "CHECKBOX")
{

for (i=0; i < obj.length; i++)
{
if (obj[i].checked)
return true;
}

return false;
}
}


function _CF_checkupform(_CF_this)

{

if (!_CF_hasValue(_CF_this.username, "TEXT" ))

{

if (!_CF_onError(_CF_this, _CF_this.username, _CF_this.username.value, "Please enter a username"))

{

return false;

}

}


return true;

}


//-->

</script>
<!-- TEXTBOX VALIDATION END-->

</HEAD>
<BODY>


<center>

<p>
<!-- ONSUBMIT FORM CALLS TEXTBOX VALIDATION-->

<FORM NAME="upform" ACTION="/cgi-bin/some-script.cgi" METHOD=POST onSubmit="return _CF_checkupform(this)" ENCTYPE="multipart/form-data">
<input type=file name=uploadfile size="20"><BR>
<INPUT TYPE="text" NAME="username" SIZE="20">

<!-- SUBMIT BUTTON CALLS UPLOAD VALIDATION-->

<input type=button name="Submit" value="Submit" onclick="LimitAttach(this.form, this.form.uploadfile.value)">
</FORM>
</center>
</BODY>

Khalid Ali
08-05-2003, 10:15 AM
Whats the error you get?

instantnet11
08-05-2003, 12:00 PM
They just both dont work together but they work by themselves fine.