Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mask Edit Box (Code Included)

Status
Not open for further replies.

790213

Programmer
Sep 22, 2003
50
0
0
ZA
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(&quot;character&quot;, - 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=&quot;form&quot; action=&quot;&quot; method=&quot;post&quot;>
<input name=&quot;Field1&quot; id=&quot;MyText&quot; value=&quot;____/__/__&quot; onKeyDown=&quot;DeleteNextChar(event);&quot; onKeyUp=&quot;MaskControl(this.value, this, '4,7', '/', event);&quot; maxlength=&quot;11&quot;>
</form>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top