PHP JAVASCRIPT HTML, upload image upon BROWSE competion


I have this little form that has a button loading a little icon onto the form itself. The button says 'browse', and there is another button says 'upload image'. I find it kinda unnecessary to have two buttons to upload the image.

How can I make the upload happen on the end of Browse ?

here's the code by the way. (The upload button just activate the js that calls a php file that does the trick, the js function updates it on the form)

<form action="includes/ajaxupload.php" method="post" name="standard_use" id="standard_use" enctype="multipart/form-data">
    <button id="image_upload_button"  onclick= "$('#upload_area').css('display','none');
    ... more func data.'); return false;" disabled>upload icon</button>

    <input type="file" id="upload_file" name="filename" size="42"/>

    <p >
    Pick a nice icon that is max 300x300 pixels please

      echo '<div id="upload_area" style="'.((($theiconname!='') && (file_exists($thumb_path.$theiconname))) ? '' : 'display:none;').'float:left;
      width:50px;height:50px;border:3px solid #000;margin-top:12px;margin-left:3px;">';
      if ($theiconname){

        if (file_exists($thumb_path.$theiconname))
          echo'<img id="the_logo" src="'.$thumb_path.$theiconname.'"/>';


Thanks in advance!




Sure! Just detect when the file input field has been changed, then submit the parent form. I notice you're using jQuery so I'll provide an answer using that:

$("#upload_file").change( function(){

Alternatively, if you're submitting this via AJAX and not actually intending to submit the form, then replace$("#standard_use").submit(); with whatever function would normally fire when someone pressed your "upload image" button.

People are also looking for solutions to the problem: mysql - Cloud SQL PHP login


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.