Click here to Skip to main content
11,708,905 members (75,283 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript
Hi,

I am trying to add a new row dynamically to a html table using a javascript function.

I am trying to populate the value for each text in each row and while doing so,I am able to add the data which has single words but if I have something like Last Name, Middle Name only the first word is being displayed ...
Can anyone suggest me what I need to modify in the function to get the whole string separated by white spaces?
Please check the below code snippet .
function addRow(tbl_name) {
           var tbody = document.getElementById(tbl_name).getElementsByTagName("TBODY")[0];
            // create row
            var row = document.createElement("TR");
            // create table cell 1
            var td1 = document.createElement("TD")
//            var abc=GetInnerText("lsTest");
var abc="Last Name";
            var strHtml1 = "<center><input id="\"Text1\"" type="\"text\"" name=" + getName + " size="\"5\"" value=" + abc + " style="\"background-color:#E2E6C8;margin:0;\"" readonly=""> </input>
Thanks!
Posted 25-May-10 4:11am
asdf999298
Edited 25-May-10 4:46am
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You are missing quotes in the value(value=Last Name).Thats why only first word is getting recognized.It should be value="Last Name"

Change the markup as below

value=\"" + abc + "\"

This will work.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 319
1 Maciej Los 235
2 Mika Wendelius 170
3 OriginalGriff 163
4 Peter Leow 139
0 OriginalGriff 9,253
1 Sergey Alexandrovich Kryukov 8,562
2 CPallini 5,189
3 Maciej Los 4,966
4 Mika Wendelius 3,856


Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 25 May 2010
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100