J
jc
A while back I posted a problem on here and got some awsome help and
insight with deleting table rows using javascript. Thank you! Well
the problem gets a bit more complex now as I need to insert rows too.
In the original problem, I needed to remove Table rows rows that did
not fit a certain condition. The resulting and working code looked
like this:
<script type="text/javascript">
var theRows = document.getElementsByTagName("TR");
var r = 0;
var strTitle = "";
while (r < theRows.length)
{ try
{ strTitle = theRows[r].innerText || theRows[r].textContent;
strTitle = strTitle.replace(/\n|\r|\t|\^ /g,"");
var row = theRows[r],
cells = row.getElementsByTagName('td');
if (cells[0].className.indexOf('ms-formlabel') > -1)
{
if (strTitle.indexOf("(HP)") == -1)
{
theRows[r].style.display = "none";
}
else
{
theRows[r].cells[0].innerHTML = theRows[r].cells
[0].innerHTML.replace("(HP)","");
}
}
}catch(err){}r+=1;
}
</script>
And it works great!
Now the challenge is that I need to insert a Row header when a certain
qualifying row is encountered under that same conidtion.
So for example, if a row contains (HP), it will fall into the
condition.. it that row has a string (H:whatever) in it, I need to
insert a row in that table, right above that qualifiying row as
follows:
The rendered html looks likes
<TR>
<TD nowrap="true" valign="top" width="190px" class="ms-
formlabel"><H3
class="ms-standardheader">
<nobr>(HP)(H:whatever) Question</nobr>
</H3></TD>
<TD valign="top" class="ms-formbody" width="400px">
The result of the new code would look like this:
<tr><td>whatever</td></tr>
<TR>
<TD nowrap="true" valign="top" width="190px" class="ms-
formlabel"><H3
class="ms-standardheader">
<nobr>Question</nobr>
</H3></TD>
<TD valign="top" class="ms-formbody" width="400px">
Thanks in advance for any help or information!
insight with deleting table rows using javascript. Thank you! Well
the problem gets a bit more complex now as I need to insert rows too.
In the original problem, I needed to remove Table rows rows that did
not fit a certain condition. The resulting and working code looked
like this:
<script type="text/javascript">
var theRows = document.getElementsByTagName("TR");
var r = 0;
var strTitle = "";
while (r < theRows.length)
{ try
{ strTitle = theRows[r].innerText || theRows[r].textContent;
strTitle = strTitle.replace(/\n|\r|\t|\^ /g,"");
var row = theRows[r],
cells = row.getElementsByTagName('td');
if (cells[0].className.indexOf('ms-formlabel') > -1)
{
if (strTitle.indexOf("(HP)") == -1)
{
theRows[r].style.display = "none";
}
else
{
theRows[r].cells[0].innerHTML = theRows[r].cells
[0].innerHTML.replace("(HP)","");
}
}
}catch(err){}r+=1;
}
</script>
And it works great!
Now the challenge is that I need to insert a Row header when a certain
qualifying row is encountered under that same conidtion.
So for example, if a row contains (HP), it will fall into the
condition.. it that row has a string (H:whatever) in it, I need to
insert a row in that table, right above that qualifiying row as
follows:
The rendered html looks likes
<TR>
<TD nowrap="true" valign="top" width="190px" class="ms-
formlabel"><H3
class="ms-standardheader">
<nobr>(HP)(H:whatever) Question</nobr>
</H3></TD>
<TD valign="top" class="ms-formbody" width="400px">
The result of the new code would look like this:
<tr><td>whatever</td></tr>
<TR>
<TD nowrap="true" valign="top" width="190px" class="ms-
formlabel"><H3
class="ms-standardheader">
<nobr>Question</nobr>
</H3></TD>
<TD valign="top" class="ms-formbody" width="400px">
Thanks in advance for any help or information!