简体   繁体   English

我无法使用javascript大写输入文本框

[英]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.

相关问题 如何在JavaScript中将用户输入转换为大写? - How do i turn user input into upper case in JavaScript? 无法使用JavaScript中的大写和小写函数转换我的字符串 - can't convert my string using upper and lower case functions in JavaScript 如何在 javascript 中不使用正则表达式使首字母大写 - How to Make First Letter Upper Case without using Regex in javascript 我如何使用纯JavaScript在数组中使输入值不区分大小写 - how can i make the input value case-insenstive in an array using pure javascript 如何使用JavaScript将所有用户输入转换为大写字母? - How can I convert all my user inputs to the upper case letter using JavaScript? 如何使正则表达式匹配大小写? - How can I make a regular expression match upper and lower case? 我怎样才能只为全名制作大写字母 - how can i make the upper case for the full name only 我想进行搜索,我可以同时搜索大写和小写..? - i want to make a search in which i can search upper case and lower case both at same time..? 如何让 JavaScript 的 replaceAll() 将带有小写和大写的字符串视为小写? - How do I make JavaScript's replaceAll() treat strings with both lower case and upper case as if they were lower case? 如何使用JavaScript使大写的变音单词的第一个字母? - How to make first letter of a word having umlaut in Upper Case using Javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM