Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating an HTML Table with JavaScript DOM
    primarykey
    data
    text
    <p>The task at hand is to dynamically create an HTML table from variable values passed to a new page through its URL. The HTML table needs four columns: <strong>Product Name</strong>, <strong>Item Number</strong>, <strong>Price</strong>, and <strong>Quantity</strong>.</p> <p>I am using the JavaScript DOM to accomplish this task. However, I cannot get my code to work properly because I think I am misusing the tBodies[0].appendChild(tr) method. I can only get the last column in my table to display. The first 3 columns do not display. Any ideas where I've gone wrong?</p> <pre><code>&lt;FORM NAME=order ACTION=submit.php METHOD=GET&gt; &lt;TABLE ID=gradient-style SUMMARY=EuroClassic Dynamic Ordering&gt; &lt;THEAD&gt; &lt;TR&gt; &lt;TH scope=col&gt;Product&lt;/th&gt; &lt;TH scope=col&gt;Item #&lt;/th&gt; &lt;TH scope=col&gt;Price&lt;/th&gt; &lt;TH scope=col&gt;Quantity&lt;/th&gt; &lt;/TR&gt; &lt;/THEAD&gt; &lt;TBODY&gt; &lt;SCRIPT language=javascript&gt; var vars = [], hash; var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&amp;'); var i = 0; while(i &lt; hashes.length) { hash = hashes[i].split('='); vars.push(hash[0]); vars[hash[0]] = hash[1]; // hasQuantity Array created to test if the Quantity Variable // is zero or not...is product ordered? var hasQuantity = new Array(); hasQuantity = hashes[i+4].split('='); // hasQuantity != 0 indicates product has been ordered... if(hasQuantity[1] != 0) { var nameProduct = hashes[i].split('='); var tr = document.createElement('tr'); var td = document.createElement('td'); var input = document.createElement('input'); input.type = "text"; input.size = 40; input.name = nameProduct[0]; nameProduct[1] = nameProduct[1].replace(/%/g,''); nameProduct[1] = nameProduct[1].replace(/2C/g,''); nameProduct[1] = nameProduct[1].replace(/2F/g,''); nameProduct[1] = nameProduct[1].replace(/28/g,''); nameProduct[1] = nameProduct[1].replace(/29/g,''); nameProduct[1] = nameProduct[1].replace(/\+/g," "); input.value = nameProduct[1]; input.readOnly = true; td.appendChild(input); tr.appendChild(td); document.getElementById('gradient-style').tBodies[0].appendChild(tr); i++; var nameItem = hashes[i].split('='); input.type = "text"; input.size = 6; input.name = nameItem[0]; input.value = nameItem[1]; input.readOnly = true; td.appendChild(input); tr.appendChild(td); document.getElementById('gradient-style').tBodies[0].appendChild(tr); i = i+4; var namePrice = hashes[i].split('='); input.type = "text"; input.size = 6; input.name = namePrice[0]; input.value = namePrice[1]; input.readOnly = true; td.appendChild(input); tr.appendChild(td); document.getElementById('gradient-style').tBodies[0].appendChild(tr); i++; var nameQuantity = hashes[i].split('='); input.type = "text"; input.size = 6; input.name = nameQuantity[0]; input.value = nameQuantity[1]; input.readOnly = true; td.appendChild(input); tr.appendChild(td); document.getElementById('gradient-style').tBodies[0].appendChild(tr); i++; } //If Quantity Ordered is Zero, Proceed to next set of variables else { i=i+7; } } &lt;/SCRIPT&gt; &lt;/TBODY&gt; &lt;/TABLE&gt; &lt;/FORM&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload