WebtextEdit execute Javascript function - javascript

I need to execute an entire javascript function.
Found what I was doing wrong:
var edit = igedit_getById("FG2100RefNo");
var editText = edit.getText();
alert(!isNaN(editText));
But, this only checks & displays a message box.
I need to execute the below javascript:
<script language=Javascript>
<!--
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
//-->
onkeypress="return isNumberKey(event)"
How can I do this with the webtextedit:
var edit = igedit_getById("FG2100RefNo");
var editText = edit.getText();
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57)) return false;
return true;
}
return isNumberKey(editText)
I only have the onkey event property value to insert the code.

You can provide the client function name to the control's ClientSideEvents.KeyPress property from the server-side.
C#:
FG2100RefNo.ClientSideEvents.KeyPress = "isNumberKey";
you'll have to update the definition of isNumberKey to accept the parameters provided and use the control's method of canceling the action.
ClientSideEvents reference:
http://help.infragistics.com/Help/NetAdvantage/ASPNET/2009.1/CLR3.5/html/Infragistics35.WebUI.WebDataInput.v9.1~Infragistics.WebUI.WebDataInput.WebTextEdit~ClientSideEvents.html

Your onkeypress="return isNumberKey(event)" function is sufficient to force user type only numerics.

Related

How to automatically add a dot after the nth character automatically in textarea?

I have to write a textarea in which the user should enter the given latitude in decimal degrees.
For example: 60.45678 or 05.1
What should I do to make a dot appear in the textarea automatically after the second character?
I already have a function to check if the characters are numbers:
<script language=Javascript>
function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
} </script>
Maybe it can be somehow modified so that it would add a dot and check if the first two numbers are smaller than 90?
<textarea name="LongitudeEW" placeholder="Longitude East/West." onkeypress="return isNumberKey(event)"></textarea>
Thanks for the help :)
Try this
var DECIMAL_REGEXP = /(?<=^.{2}$)/g;
function handleKeyUp(e) {
var target = e.target;
var charCode = e.which || e.keyCode;
if(charCode > 31 && (charCode < 48 || charCode > 57)){
return false;
}
target.value = target.value.replace(DECIMAL_REGEXP, '.');
return true;
}
var DECIMAL_REGEXP = /(?<=^.{2}$)/g;
function handleKeyUp(e) {
var target = e.target;
var charCode = e.which || e.keyCode;
if(charCode > 31 && (charCode < 48 || charCode > 57)){
return false;
}
target.value = target.value.replace(DECIMAL_REGEXP, '.');
return true;
}
<textarea name="LongitudeEW" placeholder="Longitude East/West." onkeypress="return handleKeyUp(event)"></textarea>
In case you want to bind to the elements keypress event vs inlining:
// cache the regexp
var DECIMAL_REGEXP = /(?<=^.{2}$)/g;
// ref the textarea
var textrea = document.getElementById('LongitudeEW');
// bind to the keypress event
textrea.addEventListener('keypress', function(e){
var target = e.target,
charCode = e.which || e.keyCode;
if(charCode > 31 && (charCode < 48 || charCode > 57)){
e.preventDefault();
}
target.value = target.value.replace(DECIMAL_REGEXP, '.');
});
<textarea id="LongitudeEW" name="LongitudeEW" placeholder="Longitude East/West."></textarea>
You can try using this library: https://nosir.github.io/cleave.js/
For example as your requirement. Hope to help, my friend :))
<script src="cleave.js"></script>
<input class="input-element" type="textarea" >
<script>
$(function(){
var cleave = new Cleave('.input-element', {
delimiter: '.',
blocks: [2, 100],
numericOnly: true
});
});
</script>

jQuery get numeric input from all browsers

I want the user to press on a number key while focus is on an input item, and the browser should go to foo.com/[number]
this is the code I am using:
function isNumberKey(evt){
var charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode != 46 && charCode > 31
&& (charCode < 48 || charCode > 57))
return false;
return true;
}
$(document).ready(function(){
$('.my_input').keypress(function(event){
if(isNumberKey(event)){
window.location='foo.com/'+(event.keyCode-48);
}
});
});
It works on Google Chrome, but Firefox users are getting errors. I also want to implement a mobile version where the user can input the number, and press the "enter" key of the mobile device.
How can I ensure that this will work on all browsers that support javascript?
Thanks for any help!
Here's your code corrected but I don't think this is really what you're after. Note that charcode returned from the numpad is different from the that of the number-key row.
function isNumberKey(evt){
var charCode = (evt.which) ? evt.which : evt.keyCode;
if ((charCode >= 48 && charCode <= 57) || (charCode >= 96 && charCode <= 105)) { //0-9 only (inc numpad)
return true;
}
return false;
}
$(document).ready(function(){
$("input[type='number']").on("keyup",function(evt){
if(isNumberKey(evt)){
var charCode = (evt.which) ? evt.which : evt.keyCode;
//window.location='foo.com/'+(charCode-48);
alert('foo.com/'+(charCode-48));//minus 48 wont work if numpad
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="number" value="" />
It may be better to just get the value of the input instead...
$(document).ready(function(){
$("input[type='number']").on("keyup",function(){
var val = parseInt(this.value);
this.value="";
if(val>0){
alert('foo.com/'+val);
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="number" value="" />

Allow only numbers in Textbox not working : ASP.NET

I need only numbers in textbox. This is the javascript code that I am using :
function onlyNumbers(evt) {
evt = (evt) ? evt : window.event;
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
alert(charCode);
return false;
}
return true;
}
The ASP text box on which I am calling the above function is :
<asp:TextBox ID="txtArtCount" placeholder="Numeric" onKeypress="return onlyNumbers(event);" runat="server" Width="65px" CssClass="searchTextBoxes"></asp:TextBox>
I am using Internet Explorer8 browser. I checked in Chrome as well but it is not working.
On pressing key in textbox, alert is shown but the text gets typed in the textbox as well.
code works correctly , I used input type text instead asp one , check in view source if something renders incorrectly or not
function onlyNumbers(evt) {
evt = (evt) ? evt : window.event;
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
alert(charCode);
return false;
}
return true;
}
<input type="text" ID="txtArtCount" placeholder="Numeric" onKeypress="return onlyNumbers(event);" />
hope that helps !

PL/SQL NUMBERS ONLY

I am trying to create a numbers only text box in a PL/SQL screen. I am not very familiar with PL SQL or if this would even work.
I cant get this to work. Any suggestions?
htp.p('<html><head>');
htp.p('<script type="text/avascript">
$(function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
else
return true;
});
</script>');
htp.p('</head>');
htp.p('<INPUT id="txtChar" onkeypress="return isNumberKey(event)" type="text" name="txtChar">');
You are declaring the function inside $(), thus that function is not available to the global scope. To declare it globally, use this:
htp.p('<script type="text/javascript">
function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
else
return true;
}
</script>');
Should work as expected now.
Original demo (with problem).
Fixed demo (working).

numeric validation not working in firefox

i have a textbox which i need to accept only digits.All other keys in the keyboard sholdn't generate event in the textbox.i created a javascript code
<script type="text/javascript">
function onlyNumbers(evt)
{
var e = event || evt; // for trans-browser compatibility
var charCode = e.which || e.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
</script>
html is
<asp:TextBox ID="txtFreeship" runat="server" Width="50px" onkeypress="return onlyNumbers();">
</asp:TextBox>
it is not working in mozilla firefox(working perfectly in internet explorer).can any one please answer
Call the following function on form load
function isDecimalKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && charCode > 46 && (charCode < 48 || charCode > 57)) {
return false;
}
else {
return true;
}
}
txtNoSeat.Attributes["onKeyPress"] = "Javascript:return isNumberKey(event);";

Categories

Resources