html input null,javascript - html input fileupload returning null - Stack Overflow

I am trying to make a demo involving an html input file uploader and ajax, but I can't even get my script to getElementById.

I keep receiving an TypeError: form is null.

Here is my html and script:

Upload

var form = document.getElementById("file-form");

var fileSelect = document.getElementById("file-select");

var uploadButton = document.getElementById("upload-button");

form.onsubmit = function (event) {

event.preventDefault();

// Update button text.

uploadButton.innerHTML = 'Uploading...';

}

Note that 'fileSelect' and 'uploadButton' are receiving their elements and are not null.

For some reason form is not able to getElement.

I've seen several similar questions, but it seems like I am doing the right thing. Let me know if you have any suggestions.

Thanks in advance.

EDIT: I should add that this demo is in an ASP .ascx User Control Form. kami-sama's Code Snippet worked perfectly fine, but it will not do the same in my solution.

I log the 'form' variable after getElementById and it returns null and does not proceed past the form.onsubmit = function(event) line.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值