![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||||
| |||||
|
|
However, if there's more than one link on the page, my code assigns each onclick event to all of the previous nodes in the array instead of each one independently. (I've commented the problematic line of javascript, with "THIS IS THE PROBLEM LINE"). I must be missing something! snip for(var d=0;d<docArray.length;d++) { if(docArray[d].className=='doc') { //Get values fontNode = docArray[d]; sourceHTML = fontNode.innerHTML; sourceHref=(sourceHTML.substring(sourceHTML.indexO f('"')+1,sourceHTML.indexOf('">'))); |
|
path = sourceHref.substring(sourceHref.indexOf('/',8)); doc = path.substring(path.lastIndexOf('/')+1); ext = doc.substr(doc.length - 3); docName = fontNode.innerText; //Determine image switch(sourceHTML.substr(sourceHTML.indexOf('>')-4,3)) { case 'doc' : img="msword.png"; break; case 'xls' : img="msexcel.png"; break; case 'ppt' : img="mspowerpoint.png"; break; case 'pdf' : img="pdf.png"; break; } linkNode = fontNode.children(0); |
|
linkNode.setAttribute('href','#'); |
|
imageNode = linkNode.insertBefore(document.createElement('img' ),linkNode.firstChild); imageNode.src = 'Skins/Standard/'+img; imageNode.alt = docName; linkNode.onclick = function(){loadDoc(sourceHref)};//THIS IS THE PROBLEM LINE } |
|
} } function loadDoc(filespec) { //Dummy code to test the onclick event coding alert(filespec); } window.onload = ModifyLinks; //-- /script /head body h3>Dynamically Modifying A Tags</h3 font class='doc'><a href="http://localhost:1411/UserData/Test1.doc">Document 1</a></font><br / font class='doc'><a href="http://localhost:1411/UserData/Test1.xls">Spreadsheet 1</a></font><br / font class='doc'><a href="http://localhost:1411/UserData/Test1.ppt">Presentation 1</a></font><br / font class='doc'><a href="http://localhost:1411/UserData/Test2.doc">Document 2</a></font><br / /body /html I'd be very grateful for your help - can't figure it out! Thanks very much. Regards Gary gb at prodsol dot co dot nz |
![]() |
| Thread Tools | |
| Display Modes | |
| |