Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


show hide submit button with jquery

Posted on 2010-08-24
Medium Priority
Last Modified: 2012-06-21

How would I only display the submit button below when the user has selected a file to input in the file input control.  I want the submit button to remain hidden until the do select a file to input. I'm using jquery.

<form id="uploadFrm" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data">
                        <input type="file" name="image" id="image" size="50"/>
                        <input type="submit" name="submit" value="Upload" id="submit"/>
Question by:cgray1223
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

dfendig earned 2000 total points
ID: 33518132
Try this:

add this into your javascript code:

function showSubmit()


and change your html to this

<form id="uploadFrm" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data">
                        <input type="file" name="image" id="image" size="50" onchange="showSubmit()"/>
                        <input style="display:none" type="submit" name="submit" value="Upload" id="submit"/>

Expert Comment

ID: 33518150
Display vs. Visibility
Visibility:hidden will leave space in the container for the object so youll see the gap where the submit button would be.
Display:none does not leave space in the container, and when you change it to Display:box or whatever it adds container space to show it.

Also, i didn't see the id for the submit button at the end of the input tag. You could just use $('#submit').show() instead of $('input[name=submit]').show();

Expert Comment

ID: 33518169
Can also do ...             

<script type="text/javascript">
      $("#image").live('change', function() {
            alert("I Changed ");

Just change the submit button HTML to have style="display:none"

Hope that helps.


Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question