Printable Version of Topic

Click here to view this topic in its original format

HTMLHelp Forums _ Client-side Scripting _ Using Javascript to obtain a table value

Posted by: bowlesj Mar 9 2019, 09:54 AM

Hi, I have php code below that is creating the html entry for the 2nd column of a table.

CODE
echo("<td><a href='frmKaraokeUpdateSongGroup.php?RecKey=$fldKF_Song_LU&fldKF_Key=$fldKF_Key'>$fldKF_Group</td>\n");


I am trying to get at the $fldKF_Group using javascript. I know how to find the cell and row using the command below but I can't figure out the part at the end where I mark it in bold.
var GroupCurr = document.getElementById("Table_KaraokeSchedule").rows[RowCnt].cells[1].can't figure out what to put here[color=#FF0000];


I know how to do it if there is no href in the table cell (using .innerhtml). I know how to do it if there is an input textbox in the table cell. I have some example code to find the value of the href. In the past I have used .innerhtml and used the left string or right string commands to get at the data but I prefer not to do that. Google searches with parts of the command are not finding anything.

Any help would be appreciated.

Thanks,
John

Posted by: bowlesj Mar 9 2019, 11:24 AM

I tried about 6 more things from examples I could find but had no luck. For now this is what I am forced to do. It works but I am sure there is a better way. It is strictly for my use so maybe this is all I need considering time restraints.

CODE
function funcCallShellToBIAB(fldKF_Key,fldMM_Key,RowCnt) {
    var GroupCurr = document.getElementById("Table_KaraokeSchedule").rows[RowCnt].cells[1].innerHTML;
    GroupCurr = Right(GroupCurr, 5);
    GroupCurr = Left(GroupCurr, 1);
    var GroupNext = document.getElementById("Table_KaraokeSchedule").rows[RowCnt + 1].cells[1].innerHTML;
    GroupNext = Right(GroupNext, 5);
    GroupNext = Left(GroupNext, 1);
    window.location='frmKaraoke_ShellToBIAB.php?RecKey=' + fldKF_Key + "&fldMM_Key=" + fldMM_Key + "&GroupCurr=" + GroupCurr + "&GroupNext=" + GroupNext;
}

Posted by: Christian J Mar 9 2019, 12:52 PM

QUOTE(bowlesj @ Mar 9 2019, 03:54 PM) *

CODE
echo("<td><a href='frmKaraokeUpdateSongGroup.php?RecKey=$fldKF_Song_LU&fldKF_Key=$fldKF_Key'>$fldKF_Group</td>\n");


Note that the link above is lacking its </a> end tag.

QUOTE
I know how to find the cell and row using the command below but I can't figure out the part at the end where I mark it in bold.
var GroupCurr = document.getElementById("Table_KaraokeSchedule").rows[RowCnt].cells[1].can't figure out what to put here[color=#FF0000];

The following should return the contents of the first link in the cell:

CODE
var GroupCurr = document.getElementById("Table_KaraokeSchedule").rows[RowCnt].cells[1].getElementsByTagName('a')[0].innerHTML;

If you only want the plain link text you might also use innerText instead of innerHTML.

Posted by: bowlesj Mar 9 2019, 01:59 PM

Thank you Christian, now I understand this one too.
document.getElementById("Table_KaraokeSchedule").rows[MyRow].cells[6].getElementsByTagName('input')[0].checked=false;

John

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)