Hello,
I am learning JavaScript. I have a table on HTML page:
        <table id="announcemen t_fields" border="0">
        <tbody>
        <tr>
        <td><span class="obligato ry">Offer type</span>:</td>
        <td>
            <select name="offer_typ e"
onchange="ShowA nnouncementRows ();">
                <option value="" selected>(selec t)</option>
                <option value="B">buy</option>
                <option value="H">hire</option>
                <option value="S">sell</option>
                <option value="E">excha nge</option>
            </select>
        </td>
        </tr>
        ...
        <tr>
        <td><label for="caution">C aution:</label></td>
        <td><input type="checkbox" name="caution"> </td>
        </tr>
        ...
        </tbody>
        </table>
I want table rows (with input controls) to be visible depending on the
selection of offer_type. For example, I want input caution to be visible
for offer_type = "H" or "(select)".
As you see I am calling function ShowAnnouncemen tRows() at every change of
offer_type. Here is the code:
function ShowAnnouncemen tRows()
{
var visibility = new Array( Â Â // can be more complicated
 new Array(1, 1, 1, 1, 1, 1, 1, 1),
    new Array(1, 1, 1, 1, 1, 0, 1, 1),
    new Array(1, 1, 1, 1, 1, 1, 1, 1),
    new Array(1, 1, 1, 1, 1, 0, 1, 1),
    new Array(1, 1, 1, 1, 1, 0, 1, 1)
 );
 var table = document.getEle mentById("annou ncement_fields" );
 var tbody = table.tBodies[0];
 if (announcementRo ws == null)
 {
announcementRow s = new Array();
  for (var r = 0; r < tbody.rows.leng th; r++) // remember table
  announcementRow s.push(tbody.ro ws[r].innerHTML);
 } Â
 for (var r = 1, len = tbody.rows.leng th; r < len; r++) // leave only first
row
{
 tbody.removeChi ld(tbody.lastCh ild);
  var selIdx =
document.forms["announceme nt"].elements["offer_type "].selectedIndex;
  if (selIdx -1)
  for (var r = 1; r < announcementRow s.length; r++)
   if (visibility[selIdx][r] == 1) // show visible rows
    {
    var theRow = table.createEle ment("tr"); // HERE PROBLEM!!!
     theRow.innerHTM L = announcementRow s[r];
     tbody.appendChi ld(theRow);
    }
}
I have problems with debugging JavaScript but using alerts I found that the
code executes to the line:
    var theRow = table.createEle ment("tr");
and it doesn't continue. I don't know why and how to solve the problem. I
also tried document.create Element but it is not a solution.
Please help. Thanks in advance.
/RAM/
I am learning JavaScript. I have a table on HTML page:
        <table id="announcemen t_fields" border="0">
        <tbody>
        <tr>
        <td><span class="obligato ry">Offer type</span>:</td>
        <td>
            <select name="offer_typ e"
onchange="ShowA nnouncementRows ();">
                <option value="" selected>(selec t)</option>
                <option value="B">buy</option>
                <option value="H">hire</option>
                <option value="S">sell</option>
                <option value="E">excha nge</option>
            </select>
        </td>
        </tr>
        ...
        <tr>
        <td><label for="caution">C aution:</label></td>
        <td><input type="checkbox" name="caution"> </td>
        </tr>
        ...
        </tbody>
        </table>
I want table rows (with input controls) to be visible depending on the
selection of offer_type. For example, I want input caution to be visible
for offer_type = "H" or "(select)".
As you see I am calling function ShowAnnouncemen tRows() at every change of
offer_type. Here is the code:
function ShowAnnouncemen tRows()
{
var visibility = new Array( Â Â // can be more complicated
 new Array(1, 1, 1, 1, 1, 1, 1, 1),
    new Array(1, 1, 1, 1, 1, 0, 1, 1),
    new Array(1, 1, 1, 1, 1, 1, 1, 1),
    new Array(1, 1, 1, 1, 1, 0, 1, 1),
    new Array(1, 1, 1, 1, 1, 0, 1, 1)
 );
 var table = document.getEle mentById("annou ncement_fields" );
 var tbody = table.tBodies[0];
 if (announcementRo ws == null)
 {
announcementRow s = new Array();
  for (var r = 0; r < tbody.rows.leng th; r++) // remember table
  announcementRow s.push(tbody.ro ws[r].innerHTML);
 } Â
 for (var r = 1, len = tbody.rows.leng th; r < len; r++) // leave only first
row
{
 tbody.removeChi ld(tbody.lastCh ild);
  var selIdx =
document.forms["announceme nt"].elements["offer_type "].selectedIndex;
  if (selIdx -1)
  for (var r = 1; r < announcementRow s.length; r++)
   if (visibility[selIdx][r] == 1) // show visible rows
    {
    var theRow = table.createEle ment("tr"); // HERE PROBLEM!!!
     theRow.innerHTM L = announcementRow s[r];
     tbody.appendChi ld(theRow);
    }
}
I have problems with debugging JavaScript but using alerts I found that the
code executes to the line:
    var theRow = table.createEle ment("tr");
and it doesn't continue. I don't know why and how to solve the problem. I
also tried document.create Element but it is not a solution.
Please help. Thanks in advance.
/RAM/
Comment