admin管理员组文章数量:1393900
<html>
<body>
<script language="javascript">
document.getElementById('myfileId').onchange = function(e) { alert('change'); }
</script>
<form action="" >
<input type="file" id="myfileId" name="myfile">
</form>
</body>
</html>
How can I call the JavaScript function after a file selection.
Edit: 1
<html>
<body>
<form>
<input type="file" id="myfileId" name="myfile">
</form>
<script language="javascript">
window.onload = function()
{
alert("Test");
document.getElementById('myfileId').onblur = function(e) { alert('change'); }
}
</script>
</body>
</html>
<html>
<body>
<script language="javascript">
document.getElementById('myfileId').onchange = function(e) { alert('change'); }
</script>
<form action="" >
<input type="file" id="myfileId" name="myfile">
</form>
</body>
</html>
How can I call the JavaScript function after a file selection.
Edit: 1
<html>
<body>
<form>
<input type="file" id="myfileId" name="myfile">
</form>
<script language="javascript">
window.onload = function()
{
alert("Test");
document.getElementById('myfileId').onblur = function(e) { alert('change'); }
}
</script>
</body>
</html>
Share
Improve this question
edited May 10, 2010 at 19:55
coderex
asked May 10, 2010 at 19:20
coderexcoderex
27.9k46 gold badges119 silver badges172 bronze badges
3
-
Why there is no
<html>
element! In fact, I don't even know what language this is. </sarcasm> Could you add a bit of context to your question such as what error message and behavior(expected and actual) and such? – Earlz Commented May 10, 2010 at 19:21 - For your edit, I didn't actually mean to make a full HTML document. I just meant you needed more context such as "what error message and behavior(expected and actual)" – Earlz Commented May 10, 2010 at 19:47
- @Earlz I need to call a javascript function after the selection of file from the Open Dialog window close event. – coderex Commented May 10, 2010 at 19:51
2 Answers
Reset to default 8You have to put that <script>
after the <input>
. The document.getElementById('myfileId')
does not exist if you put it before, so it will return nothing.
As @Kenny says, you have to either put the script after the input declaration so the element actually exists when the script is executed, or alternatively, add the function to the document's onload
event:
window.onload = function()
{ document.getElementById('myfileId').onchange =
function(e) { alert('change'); }
}
本文标签:
版权声明:本文标题:How to call a javascript function after the selection of file from the Open Dialog window close event. in HTMLusing html file ty 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744082438a2587895.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论