-4
      function ShowEditBox(serial) 
    {

        $("#divEditBox").slideDown("medium");
        var pserial ='PName'+ serial;
        var colindex = 0;
        var $tr = $("#" + pserial).parent().parent();

        $tr.find('td').each(function () {

            if (colindex == 2) {
                $("#txtName").val($(this).text());

            } else if (colindex == 3) {
                $("#txtSurName").val($(this).text());

            } else if (colindex == 4) {
                $("#txtEmail").val($(this).text());

            } else if (colindex == 5) {

                $("#txtMobile").val($(this).text());
            } else if (colindex == 6) {

                $("#txtAddress").val($(this).text());
            }

            colindex++;


        })

        $("#hdField").val(serial);
    }

Whenever i click the edit button in grid view that particular row data should be displayed in text boxes. But here i am getting unnecessary spaces in text boxes. How can i trim the spaces in the Text box(txtName) ?? I am getting spaces in text .

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
Ajay Finian
  • 61
  • 2
  • 13

4 Answers4

2

Try to use $.trim("string"),

 $("#txtName").val($.trim($(this).text()));
Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130
2

use trim() function of javascript

for jquery look at here Trim Look at here

example

var str = "         lots of spaces before and after         ";
$( "#original" ).html( "Original String: '" + str + "'" );
$( "#trimmed" ).html( "$.trim()'ed: '" + $.trim(str) + "'" );
Just code
  • 13,553
  • 10
  • 51
  • 93
1

Use javascript trim() method.

$("#txtName").val($(this).text().trim());
Mohit Pandey
  • 3,679
  • 7
  • 26
  • 38
0
  function ShowEditBox(serial) 
    {

        $("#divEditBox").slideDown("medium");
        var pserial ='PName'+ serial;
        var colindex = 0;
        var $tr = $("#" + pserial).parent().parent();

        $tr.find('td').each(function () {

            if (colindex == 2) {
                $("#txtName").val($.trim($(this).text()));

            } else if (colindex == 3) {
                $("#txtSurName").val($.trim($(this).text()));

            } else if (colindex == 4) {
                $("#txtEmail").val($.trim($(this).text()));

            } else if (colindex == 5) {

                $("#txtMobile").val($.trim($(this).text()));
            } else if (colindex == 6) {

                $("#txtAddress").val($.trim($(this).text()));
            }

            colindex++;


        })

        $("#hdField").val(serial);
    }
chriz
  • 1,339
  • 2
  • 16
  • 32