开发者

How can I convert to text I collect from these input fields to lower case in Javascript?

I am trying to convert any text that the user inputs in the 开发者_开发知识库following input fields to lower case how can I do that?

//collect the input fields
inputs = secWidget.getInputs();
inputs2 = secWidget2.getInputs();


You can use the toLowerCase function of javascript for that.


Assuming those methods return array of values, here is the most straightforward way to achive what you asked:

inputs = secWidget.getInputs();
for (var i = 0; i < inputs.length; i++)
   inputs[i] = inputs[i].toLowerCase();

If still no luck please post more code and explain what getInputs return.


//collect the input fields
inputs = secWidget.getInputs().toLowerCase();
inputs2 = secWidget2.getInputs().toLowerCase();


Using toLowerCase string method in Javascript.
Reference:
http://www.w3schools.com/jsref/jsref_toLowerCase.asp

use:
inputs = secWidget.getInputs().toLowerCase();


you can use toLowerCase as mentioned above and toLocaleLowerCase() which in turn takes current locale of the user/host into account


As others have said, toLowerCase() will do what you want to do. However, I would also do this in code behind the scenes. You should always validate these inputs server-side, assuming this data is being processed in any way.

Users will always be able to disable javascript.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜