javascript - Add a new line after text has been added to a textbox - Stack Overflow

I am populating a textbox using the code below. I would like to make the textbox multiline and every ti

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>

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>
Share Improve this question asked Sep 9, 2013 at 18:13 user1342164user1342164 1,46413 gold badges48 silver badges88 bronze badges 6
  • Have you tried .value = s.substring(s.length - 10) & vbcrlf); – Don Thomas Boyle Commented Sep 9, 2013 at 18:24
  • It says vbcrlf is undefined? – user1342164 Commented Sep 9, 2013 at 18:38
  • 1 Sorry I assumed since it was vb code it would work, my last attempt is for you to try \n' like in this post , stackoverflow./questions/5758161/….... hope this helps. So Possibly after your document.GetElement ... do document.write("\n"); – Don Thomas Boyle Commented Sep 9, 2013 at 18:44
  • I tried that and its throwing errors I added the document.write("\n"); after my last line – user1342164 Commented Sep 9, 2013 at 18:58
  • have you tried write('\n'); single quote? also what errors – Don Thomas Boyle Commented Sep 9, 2013 at 18:59
 |  Show 1 more ment

1 Answer 1

Reset to default 4

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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745108442a4611698.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信