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 7434521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:51:08+00:00 2026-05-29T09:51:08+00:00

Below I have a jquery code which includes a textbox where the user can

  • 0

Below I have a jquery code which includes a textbox where the user can choose a file:

var $imagefile = $('<input />')
    .attr({
        type: 'file',
        name: 'imageFile',
        id: 'imageFile'
    });

What my question is that how can I get it so that it restricts the user from picking jpeg, gif or png files? I want user to browse for a file, then click on the submit button. If the file type is correct then show confirmation message else display an alert stating “Wrong file format has been chosen for the Image”.

Below is the validation() where it displays the alerts:

function validation() {

    var marks = parseInt($("#total-weight").text());    
    var _qid = "";
    var _msg = "";

    var maxQuestions = <?php echo (int)@$_POST['textQuestion']; ?>;
    var questionsAdded = $('tr.optionAndAnswer').length;


    var alertValidation = "";
    // Note, this is just so it's declared...
    $("tr.optionAndAnswer").each(function() {


        _qid = $("td.qid",this).text();
        _msg = "You have errors on Question Number: " + _qid + "\n";

        $(".textAreaQuestion",this).each(function() {



            if (!this.value || this.value.length < 5) {
                alertValidation += "\n\u2022 You have not entered a valid Question\n";
            }

            if (alertValidation != "") {
                return false; //Stop the each loop 
            }
        });


        $(".txtWeightRow",this).each(function() {


            if (!this.value) {
                alertValidation += "\n\u2022 Please enter in a figure for Number of Marks for this Question\n";
            }

            if (alertValidation != "") {
                return false; //Stop the each loop 
            }
        });


        if(alertValidation != ""){
            return false;
        }
    });
  • 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-29T09:51:09+00:00Added an answer on May 29, 2026 at 9:51 am

    The <input type="file"> has long (since it was introduced in 1995) had an accept attribute, where you can list MIME-types that you want to accept, e.g. accept="image/*". It’s only very recently that browsers have started to support it, though. Right now, Opera 11, Chrome 16, Firefox 9. IE doesn’t.

    Can’t recall whether the use of accept actually filters the files listed in the file selection dialog box, or just restricts the files accepted after the user has selected them. May vary from browser to browser and OS to OS.

    But yes, you can check the file extension after the file has been selected. Something like (untested):

    var allowedTypes = ["jpg", "jpeg", "gif", "png"];
    
    var path = $imagefile.val();
    var ext = path.substring(path.lastIndexOf('.') + 1).toLowerCase();
    
    if ($.inArray(ext, allowedTypes) < 0) {
       alertValidation += '\n\u2022 Unsupported file type';
    }
    

    In any event, you’ll want to validate the file types on the server, and not depend on the client to ensure they’re the right type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using JQuery. I have below JQuery Code which working fine in Firefox,
The below code is very simple. I have a jQuery autocomplete bound to an
I have this javascript code below that uses jquery, it is suppoed to be
I am getting JQUERY undefined error. Do you have any idea (code below). <%@
I have a simple bit of jQuery which displays the row below the current
Below I have some code which basically animates a div from the bottom of
I have this ajax jquery code: var form = document.getElementById('frm'); var data_string = form.serialize();
I have a jQuery code which works perfect on desktop browsers; $(span#checkbox_err).mouseout(function () {
I have a jQuery Timepicker code below: $('#timepicker').timepicker({ showOn: 'button', button: '.timepicker_button_trigger' }); This
I have the following JQuery code: jQuery(function($) { $j(.follow_btn) .click( function() { var element

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.