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

  • SEARCH
  • Home
  • 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 7784117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:02:38+00:00 2026-06-01T20:02:38+00:00

Below is my javascript code and what I want to happens is that when

  • 0

Below is my javascript code and what I want to happens is that when the user clicks on the “Upload” button in the form, it does a check in the “imageValidation” to see if the file input is correct, if so then it goes onto the “startImageUpload()” function, if file input is incorrect then it should display an alert stating “not an image” and it shouldn’t go to the ‘startImageUpload’ function.

Problem is that it is not doing this at all. When the user clicks on the “Upload” button then no alert appears, no upload happens, nothing happens. What do I need so that I can achieve the above paragraph?

Below is the form:

var $fileImage = $("<form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='imageClickHandler(this); return false;' class='imageuploadform' >" + 
"<label> Image File: <input name='fileImage' type='file' class='fileImage' /></label><br/>" +
"<input type='submit' name='submitImageBtn' class='sbtnimage' value='Upload' /></label></form>");

Below is the function where when the user clicks on the “Upload” button, it follows this function below:

  function imageClickHandler(){ 
     if(imageValidation()){ 
     startImageUpload(imageuploadform); 
     } 
}

Below is the imageValidation() function where it validates the file input but I do not know if this is working correctly?

function imageValidation() {

        $(".fileImage").change(function() {

          var val = $(this).val();

        switch(val.substring(val.lastIndexOf('.') + 1).toLowerCase()){
            case 'gif': case 'jpg': case 'png':
                return true;
                break;
            default:
                $(this).val('');
                // error message here
                alert("not an image");
                return false;
                break;
        }

    });

    }

Below is the ‘startImageUpload()’ function which I know it works before attempting to validate the input file.

function startImageUpload(imageuploadform){

  $(imageuploadform).find('.imagef1_upload_process').css('visibility','visible');
  $(imageuploadform).find('.imagef1_cancel').css('visibility','visible');
  $(imageuploadform).find('.imagef1_upload_form').css('visibility','hidden');
  sourceImageForm = imageuploadform;

      return true;
}  
  • 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-06-01T20:02:39+00:00Added an answer on June 1, 2026 at 8:02 pm

    your onsubmit always returns false…

    change it to return the result of imageClickHandler

     <form .... onsubmit="return imageClickHandler(this);">
    

    and change the JS function to return value

     function imageClickHandler(form){ 
          if(imageValidation()){ 
              return startImageUpload(form); 
          } 
          return false;
      }
    

    also – make sure that your imageValidation function has a default return value (add return false; at the last row of the function)

    EDIT:

    in order to prevent the validation from being happened when the user chooses file, remove the listening to the change event, and change your validation to:

    function imageValidation() {
        var val = $(".fileImage").val();
        switch(val.substring(val.lastIndexOf('.') + 1).toLowerCase()){
            case 'gif':
            case 'jpg': 
            case 'png':
                 return true;
            default:
                $(".fileImage").val('');
                // error message here
                alert("not an image");
                return false;
        }
        return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What happens is that if a user clicks on the 'Get Session Id' button.
I have this javascript code below that uses jquery, it is suppoed to be
Below is my javascript and form code where it appends a question number (qnum)
I have the javascript code below which disables an asp.net button during page postback.
HI all, Below mentioned javascript code works fine in all browsers including chrome(from second
Consider the JavaScript code below, inspired from the YUI documentation on YAHOO.lang.extend . In
I've simplified my JavaScript code to the example below; this code is giving me
I have a dialog box, created with the code javascript and HTML generated below.
I am creating a chunk of HTML/JavaScript with the below code: $result = mysql_query(SELECT
What does the below JavaScript mean? Why is the function embedded inside ()? (function()

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.