/    Sign up×
Community /Pin to ProfileBookmark

Form Validation & File Upload Validation

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>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliAug 05.2003 — Whats the error you get?
Copy linkTweet thisAlerts:
@instantnet11authorAug 05.2003 — They just both dont work together but they work by themselves fine.
×

Success!

Help @instantnet11 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.21,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...