Results 1 to 11 of 11
  1. #1
    Join Date
    Jul 2004
    Posts
    868

    Question Javascript: problem with changing content of a table

    Hello ,
    I have problem with changing content of a Dynamic table in FireFox ! ( mean its working fine in IE )
    since i created the table dynamically i am using following function to change contents of the table .

    Code:
    function test1(text,row,col){
    		var x=document.getElementById('tableid').rows[row].cells;
      		x[col].innerHTML=text;
     return;
     }
    its working fine in IE but its showing following error in firefox ( in debung section )

    Code:
    Error: x[col] has no properties.
    but if i change the input of rows to a static one its working fine ! but its updating just content of a row !

  2. #2
    Join Date
    Dec 2007
    Location
    Lebanon
    Posts
    413
    Quote Originally Posted by goolex View Post

    but if i change the input of rows to a static one its working fine ! but its updating just content of a row !
    please explain this more so that I try to help

  3. #3
    Join Date
    Jul 2004
    Posts
    868
    Quote Originally Posted by Codebird View Post
    please explain this more so that I try to help
    ok
    instead of that function i did a test , maybe this show my problem ,

    following code works fine :
    Code:
    var x=document.getElementById('tableid').rows[1].cells;
    x[1].innerHTML="test";
    following code also works without anyproblem ! :
    Code:
    var x=document.getElementById('tableid').rows[1].cells;
    x[1].innerHTML="test";
    
    var x2=document.getElementById('tableid').rows[1].cells;
    x2[2].innerHTML="test";
    But these codes are not working !
    Code:
    var x=document.getElementById('tableid').rows[1].cells;
    x[1].innerHTML="test";
    
    var x2=document.getElementById('tableid').rows[2].cells;
    x2[2].innerHTML="test";
    i found out when i am tring to use a new row its not working and show that error ( only in FF and opera ) ...

    its ok when i need to change contents of a row but sometimes i need to change contents of some rows ( mean more than 1 )

  4. #4
    Join Date
    Dec 2007
    Location
    Lebanon
    Posts
    413
    try using words other than row and col inside the []

  5. #5
    Join Date
    Jul 2004
    Posts
    868
    no difference !
    if you see my second post i didnt used any variable ! and its not working :\

  6. #6
    Join Date
    Dec 2007
    Location
    Lebanon
    Posts
    413
    the problem is that I am not understanding very much what works and what don't, would you show me the src files and I'll help

  7. #7
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    How many rows and columns in your table? You know these are zero-based arrays, right? (so with 2 rows and 2 columns you'd use indexes 0 and 1)
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  8. #8
    Join Date
    Jul 2004
    Posts
    868
    >foobic
    the table is dynamic , number of columns is 10 and number of rows is dynamic , between 1 to 50 ...

    >You know these are zero-based arrays, right? (so with 2 rows and 2 columns you'd use indexes 0 and 1)
    yes , in here its only for testing ...

  9. #9
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    Then install Firebug, inspect the DOM and issue your commands directly at the console. The only reason I can see for that error you're getting is if the index you use (2 in the code above) is outside the range for your rows / columns.
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  10. #10
    Join Date
    Dec 2007
    Location
    Lebanon
    Posts
    413
    I don't think that this is the problem cause he's for sure passing the same numbers as the static ones to the function

  11. #11
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    The real problem may or may not be related but in the test code shown I see only one character making the difference between working and not:
    Quote Originally Posted by goolex View Post
    following code also works without anyproblem ! :
    Code:
    var x=document.getElementById('tableid').rows[1].cells;
    x[1].innerHTML="test";
    
    var x2=document.getElementById('tableid').rows[1].cells;
    x2[2].innerHTML="test";
    But these codes are not working !
    Code:
    var x=document.getElementById('tableid').rows[1].cells;
    x[1].innerHTML="test";
    
    var x2=document.getElementById('tableid').rows[2].cells;
    x2[2].innerHTML="test";
    (bold modified to highlight the change)
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •