我想在点击图片时使用javascript提交表单。单击实际的提交按钮,但不是javascript提交。
<img class='File' src="imagehere" onclick="editFileName()"/>
<script>
function editFileName() {
var fileName = prompt("Type in name:");
if (fileName != null) {
document.getElementById('editNameField').value = fileName;
//tried these two
document.EditFileName.submit();
document.getElementById('test').submit();
}
}
</script>
@using (Html.BeginForm("EditUploadedFileName", "Folder", new { name = "EditFileName", id = "test" }))
{
<input type="hidden" id="editNameField" value="a">
<input type="hidden" id="blobName" value="a">
<input type="submit"/>
}
修改
更正按钮错误。它与此无关,与我插入代码时的拼写错误无关。贬低任何理由?吉兹
答案 0 :(得分:0)
<input type="submit"/>
将按钮更改为输入,它应该可以工作。
答案 1 :(得分:0)
试试这个
document.forms["test"].submit();
答案 2 :(得分:0)
想出了一个有效但不太好看的解决方案..
<script>
function editFileName() {
var fileName = prompt("Type in name");
if (fileName != null) {
document.getElementById('editFileName').value = fileName;
document.getElementById("SubmitEdit").click();
}
}
</script>
@using (Html.BeginForm("EditUploadedFileName", "Folder", new { blobName = file.BlobName }))
{
<input type="hidden" name="editFileName" id="editFileName" />
<input type="submit" id="SubmitEdit" style="display:none;" />
}