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">
<fieldset>
<button id="image_upload_button" onclick= "$('#upload_area').css('display','none');
$('#upload_area').fadeIn('slow');ajaxUpload(this.form,'includes/ajaxupload.php?filename=filename&maxSize=200000&
... 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
</p>
<?php
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.'"/>';
}
}
?>
</div>
</fieldset>
</form>
Thanks in advance!
Answer
Solution:
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:
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.