我有下面的代码来上传照片。我目前已经设置了流程,因此它会在单击提交按钮时上传。如何在没有提交按钮的情况下更改此代码以自动上传?谢谢
HTML:
<form data-ajax="false" id="imageform" action="imageup.php" method="POST" enctype="multipart/form-data" name="form">
<a id="companylink" href="">
<div id="yourBtn" onclick="getFile()" onchange="readURL(this);">
<img id="companyprofileimg" src="image/<?php echo $row['photo']?>"/>
</div>
<span id="cetext"><?php echo $row['username']?></span>
</a>
<div style='height: 0px;width: 0px; overflow:hidden;'>
<input id="upfile" type="file" value="upload" name="file" onchange="readURL(this);"/>
</div>
<a data-theme="g" data-ajax="false" data-role="button" id="imagesub" onclick="$('#imageform').submit();" aria-disabled="false">Upload Image</a>
</form>
JAVASCRIPT:
function getFile(){
document.getElementById("upfile").click();
}
function sub(obj){
var file = obj.value;
var fileName = file.split("\\");
document.getElementById("companyprofileimg").innerHTML = fileName[fileName.length-1];
document.myForm.submit();
event.preventDefault();
document.getElementById('imageform').submit();
}