How to insert tab character (space) inside a textbox in ASP.NET C# web application (prevent tab button to move to next control)
I need to add Horizontal space on tab key press.
Hi vidyarv,
Refer below sample.
HTML
<html xmlns="http://www.w3.org/1999/xhtml"> <title></title> <script type="text/javascript"> function AddSpace(element, event) { if (event.keyCode == 9 || event.which == 9) { event.preventDefault ? event.preventDefault() : (event.returnValue = false); var select = element.selectionStart; element.value = element.value.substring(0, element.selectionStart) + " " + element.value.substring(element.selectionEnd); element.selectionEnd = select + 1; } } </script> </head> <body> Enter : <input type="text" id="txtName" name="txtName" onkeydown="AddSpace(this,event)" /> </body> </html>
Demo
© COPYRIGHT 2025 ASPSnippets.com ALL RIGHTS RESERVED.