PHP Developers Network
http://forums.devnetwork.net/

Using Javascript to access an html table
http://forums.devnetwork.net/viewtopic.php?f=13&t=147879
Page 1 of 1

Author:  bowlesj [ Sat Mar 09, 2019 10:02 am ]
Post subject:  Using Javascript to access an html table

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

Syntax: [ Download ] [ Hide ]
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


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 (as shown below) 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

So this is my sneaky way around not having the proper solution which does get the value.
Syntax: [ Download ] [ Hide ]
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);
        var mytest = 0;
        var mytest2 = 0;
        //window.location='frmKaraoke_ShellToBIAB.php?RecKey=' + fldKF_Key + "&fldMM_Key=" + fldMM_Key + "&GroupCurr=" + GroupCurr + "&GroupNext=" + GroupNext;
}
 

Author:  pickle [ Fri Mar 22, 2019 10:00 am ]
Post subject:  Re: Using Javascript to access an html table

If I were you I'd add an id to the <a />. That way you can reference it with:
Syntax: [ Download ] [ Hide ]
document.querySelector('#id-of-tag').style.fontWeight = 'bold';

Author:  bowlesj [ Fri Mar 22, 2019 12:37 pm ]
Post subject:  Re: Using Javascript to access an html table

Thanks pickle.

Actually someone on an html forum taught me the solution below. However I would like to try your method to see if I can get it to work and I can learn something new. So I emailed myself the link to this forum thread as a reminder to eventually get around to trying it.

John


Syntax: [ Download ] [ Hide ]
function funcCallShellToBIAB(fldKF_Key,fldMM_Key,RowCnt) {
    var GroupCurr = document.getElementById("Table_KaraokeSchedule").rows[RowCnt].cells[1].getElementsByTagName('a')[0].innerHTML; //The a name is the anchor which is between <a and </a>
    //var GroupCurr = document.getElementById("Table_KaraokeSchedule").rows[RowCnt].cells[1].getElementsByTagName('a')[0].innerText; //This gives the same value but in double quotes as text
    var GroupNext = document.getElementById("Table_KaraokeSchedule").rows[RowCnt + 1].cells[1].getElementsByTagName('a')[0].innerHTML; //The a name is the anchor which is between <a and </a>
    //var GroupNext = document.getElementById("Table_KaraokeSchedule").rows[RowCnt + 1].cells[1].getElementsByTagName('a')[0].innerText; //This gives the same value but in double quotes as text
    window.location='frmKaraoke_ShellToBIAB.php?RecKey=' + fldKF_Key + "&fldMM_Key=" + fldMM_Key + "&GroupCurr=" + GroupCurr + "&GroupNext=" + GroupNext;
}
 

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/