留言板

Restrict Text Field to Numbers Only Problem

Dean Grobler,修改在12 年前。

Restrict Text Field to Numbers Only Problem

thumbnail
Ravi Kumar Gupta,修改在12 年前。

RE: Restrict Text Field to Numbers Only Problem

Liferay Legend 帖子: 1302 加入日期: 09-6-24 最近的帖子
Its working for me.. emoticon
thumbnail
Ravi Kumar Gupta,修改在12 年前。

RE: Restrict Text Field to Numbers Only Problem

Liferay Legend 帖子: 1302 加入日期: 09-6-24 最近的帖子
Can you please see in firebug console or firefox error console for any error, if appearing.. emoticon
Dean Grobler,修改在12 年前。

RE: Restrict Text Field to Numbers Only Problem

thumbnail
Sandeep Nair,修改在12 年前。

RE: Restrict Text Field to Numbers Only Problem

Liferay Legend 帖子: 1744 加入日期: 08-11-6 最近的帖子
You are missing a semicolon in the following line

var charCode = (evt.which) ? evt.which : event.keyCode;

Its working fine for me after i put that

Regards,
Sandeep
thumbnail
Ravi Kumar Gupta,修改在12 年前。

RE: Restrict Text Field to Numbers Only Problem

Liferay Legend 帖子: 1302 加入日期: 09-6-24 最近的帖子
Sandeep Nair:
You are missing a semicolon in the following line

var charCode = (evt.which) ? evt.which : event.keyCode;

Its working fine for me after i put that

Regards,
Sandeep


Hi Sandeep,

In which browser you checked.. for FF/Chrome, It worked fine for me.. with no change at all.. emoticon

Well, for semicolon, I did search on google and found this.. http://mislav.uniqpath.com/2010/05/semicolons/
This might help those who need an answer for "Why Semicolon".. Though one line says that "There is no javascript interpreter which cant handle this'" emoticon
thumbnail
Jan van der Kaaden,修改在12 年前。

RE: Restrict Text Field to Numbers Only Problem (答复)

Junior Member 帖子: 28 加入日期: 11-3-20 最近的帖子
Hi Dean,
I played a litte with the script you posted and did not succeed to make it work for me, its like i can only receive non alfanumeric key-codes. As an alternative i did the fallowing:

i changed the " Max length" field to:
<tr height="35px"><td width="50%">Max Length:</td><td><input type="text" value="" name="maxLength" class="textBoxes" onkeyup="this.value = <portlet:namespace/>isNumberKey(this.value)"></td></tr>

where the portlet:namespace tag makes the script unique for the portlet

and i changed the script to:

function <portlet:namespace/>isNumberKey(evt){
if(isNaN(evt)){
return evt.substr(0,evt.length-1);
}
return evt;
}

Of course this is not bug-free because the user can still enter a value in the middle of the entered text but it shows the way you can manipulate your input on the fly emoticon
Hope this was useful