473,382 Members | 1,258 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

javascript not woking in ie7

chathura86
227 100+
hi

i wrote the following code to populate a table dynamically

it works perfectly on Firefox

but not in IE 7
does not show any errors on IE7 either

please help me

chathura bamunusinghe

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Untitled Document</title>
  6. <script language="javascript">
  7.     //itemname, key, unitprice, warranty, Description, brand
  8.     //generate this array using php
  9.     var selectboxoptions = new Array     
  10.                         (    
  11.                             new Array ("-SELECT-", 0, 0, "-NULL-", "-NULL-", new Array("-NULL-")),
  12.                             new Array ("Key Board", 1, 500.00, "12 months", "aaaaaaaaaaaa", new Array("Samsung", "Sony", "Azus")),     
  13.                             new Array ("Mouse", 2, 1500.00, "6 months", "sssssssssssss", new Array("Hitachi", "Sony", "Azus")), 
  14.                             new Array ("LCD", 3, 2500.00, "9 months", "ddddddddddddd", new Array("Hitachi", "Samsung", "Azus"))
  15.                         );
  16.  
  17.     //load item and fill the row
  18.     function loadItem(selecteditem,  rownumber){
  19.         var rows = document.getElementById('tbl').getElementsByTagName('tr');
  20.         var row = rows[rownumber-1];
  21.         var columns = row.getElementsByTagName('td');
  22.         var itemid = searchItem(selecteditem);
  23.         columns[2].innerHTML = selectboxoptions[itemid][2];
  24.         columns[5].innerHTML = selectboxoptions[itemid][3];
  25.         columns[6].innerHTML = selectboxoptions[itemid][4];
  26.  
  27.         var selectBrand = document.createElement("select");
  28.         for(i = 0; i < selectboxoptions[itemid][5].length; i++) selectBrand.options[i] = new Option(selectboxoptions[itemid][5][i], selectboxoptions[itemid][5][i]);
  29.         columns[4].appendChild(selectBrand);
  30.     }
  31.  
  32.     //reset counter onload
  33.     function onLoad(){
  34.         var noofrows = document.getElementById('noofrows');
  35.         noofrows.value = 0;
  36.     }
  37.  
  38.     //search the item and return array index
  39.     function searchItem(itemid){
  40.         for(i=0; i<selectboxoptions.length; i++){
  41.             if(selectboxoptions[i][1] == itemid) return i;
  42.         }
  43.         return -1;
  44.     }
  45.  
  46.     //add new row
  47.     function addRow(id, noofrows){
  48.  
  49.         var noofrows = document.getElementById(noofrows);
  50.         var count = parseInt(noofrows.value);
  51.         count++;
  52.  
  53.         var tbody = document.getElementById(id);
  54.  
  55.         var row = document.createElement("tr");
  56.  
  57.         //column 1
  58.         var td1 = document.createElement("td");
  59.         td1.appendChild(document.createTextNode(count));
  60.  
  61.         //column 2
  62.         var td2 = document.createElement("td");
  63.         var selectbox1 = document.createElement("select");
  64.         //selectbox1.setAttribute("onchange", loadItem(count));
  65.         selectbox1.onchange = function() {
  66.             loadItem(this.options[this.selectedIndex].value, count);
  67.         }        
  68.         for(i = 0; i < selectboxoptions.length; i++) selectbox1.options[i] = new Option(selectboxoptions[i][0], selectboxoptions[i][1]);
  69.         td2.appendChild(selectbox1);
  70.  
  71.         //column 3
  72.         var td3 = document.createElement("td")
  73.         td3.appendChild (document.createTextNode(" "))
  74.  
  75.         //column 4
  76.         var td4 = document.createElement("td")
  77.         var selectbox2 = document.createElement("select");
  78.         for(i = 0; i < 15; i++) selectbox2.options[i] = new Option(i+1, i+1);
  79.         td4.appendChild(selectbox2);
  80.  
  81.         //column 5
  82.         var td5 = document.createElement("td")
  83.         td5.appendChild (document.createTextNode("-"))
  84.  
  85.         //column 6
  86.         var td6 = document.createElement("td")
  87.         td6.appendChild (document.createTextNode("-"))
  88.  
  89.         //column 7
  90.         var td7 = document.createElement("td")
  91.         td7.appendChild (document.createTextNode("-"))
  92.  
  93.         row.appendChild(td1);
  94.         row.appendChild(td2);
  95.         row.appendChild(td3);
  96.         row.appendChild(td4);
  97.         row.appendChild(td5);
  98.         row.appendChild(td6);
  99.         row.appendChild(td7);
  100.  
  101.         tbody.appendChild(row);
  102.         noofrows.value = count;
  103.      }
  104. </script>
  105. </head>
  106.  
  107. <body onload="onLoad()">
  108. <input type="hidden" value="0" id="noofrows" />
  109. <table id="tbl">
  110.  
  111. </table>
  112. <a href="#" onclick="addRow('tbl', 'noofrows')">add row</a>
  113.  
  114. </body>
  115. </html>
  116.  
Jul 13 '08 #1
3 2326
acoder
16,027 Expert Mod 8TB
You need to append it to the tbody instead of the table - see this link.
Jul 13 '08 #2
chathura86
227 100+
Thanks a lot

it works perfectly in ie7 now

chathura bamunusinghe
Jul 17 '08 #3
acoder
16,027 Expert Mod 8TB
Glad to hear it and you're welcome :)
Jul 17 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.