Hi Guys,
I'm creating a mask edit box. You can copy and paste the code below. Problem I'm having is that when I get to the delimiter I want to either jump to the next character or simulate a delete & delimiter effect(Preferrable). Maybe one of you can figure this one out. I've tried just about everything. It's so close to being done except for this one glitch.
<html>
<head>
<title>Untitled</title>
<script>
function MaskControl(Str, Control, DelimiterPositions, Delimiter, evt)
{
if (NumericKeyPressed(evt) == true)
{
var arrayPosition = DelimiterPositions.split(',');
var CursorPosition = GetCursorPosition(Control);
for (var i = 0; i <= arrayPosition.length; i++)
{
if (parseInt(CursorPosition) == parseInt(arrayPosition))
{
window.event.keyCode = 39;
}
}
}
}
function DeleteNextChar(evt)
{
if (NumericKeyPressed(evt) == true)
{
window.event.keyCode = 46;
}
}
function GetCursorPosition(Control)
{
if (Control.createTextRange)
{
selectedRange = document.selection.createRange().duplicate();
selectedRange.moveStart("character", - Control.value.length);
pos = selectedRange.text.length;
return pos;
}
else
{
return Control.selectionEnd;
}
}
function NumericKeyPressed(evt)
{
evt = (evt) ? evt : ((window.event) ? event : null);
if (evt)
{
var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if (elem)
{
var CharCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
if ((CharCode > 47 && CharCode < 58) || (CharCode == 191))
{
return true;
}
else
{
return false;
}
}
}
}
</script>
</head>
<body>
<form name="form" action="" method="post">
<input name="Field1" id="MyText" value="____/__/__" onKeyDown="DeleteNextChar(event);" onKeyUp="MaskControl(this.value, this, '4,7', '/', event);" maxlength="11">
</form>
</body>
</html>
I'm creating a mask edit box. You can copy and paste the code below. Problem I'm having is that when I get to the delimiter I want to either jump to the next character or simulate a delete & delimiter effect(Preferrable). Maybe one of you can figure this one out. I've tried just about everything. It's so close to being done except for this one glitch.
<html>
<head>
<title>Untitled</title>
<script>
function MaskControl(Str, Control, DelimiterPositions, Delimiter, evt)
{
if (NumericKeyPressed(evt) == true)
{
var arrayPosition = DelimiterPositions.split(',');
var CursorPosition = GetCursorPosition(Control);
for (var i = 0; i <= arrayPosition.length; i++)
{
if (parseInt(CursorPosition) == parseInt(arrayPosition))
{
window.event.keyCode = 39;
}
}
}
}
function DeleteNextChar(evt)
{
if (NumericKeyPressed(evt) == true)
{
window.event.keyCode = 46;
}
}
function GetCursorPosition(Control)
{
if (Control.createTextRange)
{
selectedRange = document.selection.createRange().duplicate();
selectedRange.moveStart("character", - Control.value.length);
pos = selectedRange.text.length;
return pos;
}
else
{
return Control.selectionEnd;
}
}
function NumericKeyPressed(evt)
{
evt = (evt) ? evt : ((window.event) ? event : null);
if (evt)
{
var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if (elem)
{
var CharCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
if ((CharCode > 47 && CharCode < 58) || (CharCode == 191))
{
return true;
}
else
{
return false;
}
}
}
}
</script>
</head>
<body>
<form name="form" action="" method="post">
<input name="Field1" id="MyText" value="____/__/__" onKeyDown="DeleteNextChar(event);" onKeyUp="MaskControl(this.value, this, '4,7', '/', event);" maxlength="11">
</form>
</body>
</html>