Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 918363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:21:47+00:00 2026-05-15T18:21:47+00:00

This is a trivial question, but for some reason I am having trouble with

  • 0

This is a trivial question, but for some reason I am having trouble with it.

I have HTML for uploading a file such as the following.

 <input type="file" name="settings">

And all I need to do is check when the form is submitted that a value has been selected.
I dont need help with the code for the form submission, I just need help since I am guessing
you are unable to validate this as you would other form input fields such as text boxes.

I have tried doing things like…
var file = document.getElementById('settings').value;
if(file.length > 0 == false){
//give error messsage here

I know that there should be an easy fix for this but I cant quite figure it out.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:21:48+00:00Added an answer on May 15, 2026 at 6:21 pm
    <input type="file" name="field_name" onchange="validate_file_format('field_name','allowed file format as comma separeated')"/>
    
    Ex:
    <input type="file" name="sitemap_doc" onchange="validate_file_format('sitemap_doc','doc,pdf')"/>
    
    
    JS Code:
    ======
    function validate_file_format(field_name, allowed_ext){
        obj1=document.req_form;
        var temp_field= 'obj1.'+field_name+'.value';
        field_value=eval(temp_field);
        if(field_value!=""){
            var file_ext= (field_value.substring((field_value.lastIndexOf('.')+1)).toLowerCase());
            ext=allowed_ext.split(',');
            var allow=0;
            for ( var i=0; i < ext.length; i++) {
                    if(ext[i]==file_ext){
                        allow=1;
                    }
            }
            if(!allow){
                alert('Invalid File format. Please upload file in '+allowed_ext+' format');        
                return false;
            }
        }
        return false;
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for such a trivial question, but I'd feel silly building this if it
This seems like such a trivial question to ask, but it's been vexing me
I'm really embarrassed to ask such a trivial question but debugging some software now
I realise this is a trivial question but I don't have access to a
This might be a trivial question for some, but I could not find the
I have a feeling this is a rather trivial question, but I'm stumped. In
Seems a trivial question, but surprisingly, found only some solutions like this one ,
This may sound like a simple and trivial question, but I'm using the following
This may be an old and trivial question but I have been struggling to
This must be a trivial question to some, but I haven't found any actual

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.