How to add a semicolon to the text in asp.net text box (web application), on pressing enter and move the cursor to next line?
Advertisement
Answer
Here is a solution using pure JavaScript.
HTML
<asp:TextBox ID="DemoTextBox" runat="server"
CssClass="textarea"
TextMode="MultiLine"/>
Code Behind (onclick javascript event wire up)
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
DemoTextBox.Attributes.Add("onkeypress", "AppendSemiColon(this, event)");
}
}
JavaScript
function AppendSemiColon(objTextBox, evt) {
if (evt.keyCode == 13) {
objTextBox.value += ";";
}
}