[英]I can't make input textbox in upper case using javascript
I am making a program wherein all textboxes are converted into UPPERCASE through CSS. 我正在编写一个程序,其中所有文本框都通过CSS转换为大写。 In my Javascript, I want to pass it to server with the same values as UPPERCASE, too.
在我的Javascript中,我也想使用与大写相同的值将其传递给服务器。 However, I encountered an error:
但是,我遇到了一个错误:
"Uncaught TypeError: Cannot read property 'toUpperCase' of undefined"
“未捕获的TypeError:无法读取未定义的属性'toUpperCase'”
I already tried different solutions from different users of StackOverFlow such as Uncaught TypeError: Cannot read property 'toUpperCase' of undefined but still error. 我已经尝试过来自StackOverFlow不同用户的不同解决方案,例如Uncaught TypeError:无法读取未定义但仍然存在错误的属性“ toUpperCase” 。
Here's my code: 这是我的代码:
// put all gathered data in an array variable so as to send to the server for saving
var param = new Array();
param[0] = clientType;
param[1] = catv_provider;
param[2] = existing_subs;
param[3] = gender;
param[4] = lastname;
param[5] = firstname;
param[6] = midname;
var param2 = [];
for (var i = 0; i < param.length; i++) {
param2[i] = param[i].toUpperCase();
}
It's because you are getting value undefined
. 这是因为您获得的价值
undefined
。
You can modify your loop as 您可以将循环修改为
for (var i = 0; i < param.length; i++) {
if(typeof(param[i])!=="undefined") { //skipping undefined
param2[i] = param[i].toUpperCase();
}
}
Try Following 尝试以下
for (var i = 0; i < param.length; i++) {
if(param[i] != null){
param[i].toUpperCase();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.