user1342164
user1342164

Reputation: 1454

Add a new line after text has been added to a textbox

I am populating a textbox using the code below. I would like to make the textbox multiline and every time the code is executed it appends the new text to a new line.

Is there a way to do this using the code below?

  <script language="javascript" type="text/javascript">
    function getSelected(source, eventArgs) {
        var s = $get("<%=NameTextBox.ClientID %>").value;
        document.getElementById('<%= NPTextBox.ClientID %>').value = s.substring(s.length - 10);
    }
</script>

Upvotes: 3

Views: 7670

Answers (1)

Karl Anderson
Karl Anderson

Reputation: 34846

Use the newline character ('\n'), like this:

<script language="javascript" type="text/javascript">
    function getSelected(source, eventArgs) {
        var s = $get("<%=NameTextBox.ClientID %>").value;
        document.getElementById('<%= NPTextBox.ClientID %>').value += s.substring(s.length - 10) + '\n';
    }
</script>

Upvotes: 4

Related Questions