[thelist] DOM ol li listing issue, Please Help!!!
Christian Heilmann
codepo8 at gmail.com
Mon Aug 15 06:01:09 CDT 2005
You are going about this the completely wrong way. Don't make your
sites dependent on JavaScript, especially not with non-existant
protocols like "javascript:".
A solution to your issue:
Start with a server side fallback for the same functionality:
<a href="list.php" id="listcreate">create list</a>
(I will not do the PHP here...)
then add a JavaScript to do it client side, for example:
function makelists()
{
if(!document.getElementById || !document.createTextNode){return;}
var listtrigger=document.getElementById('listcreate');
if(!listtrigger){return;}
listtrigger.onclick=function()
{
var items=new Array('One','Two','Three','and so on');
var newol=document.createElement('ol');
var newli;
for(var i=0;i<items.length;i++)
{
newli=document.createElement('li');
newli.appendChild(document.createTextNode(items[i]));
newol.appendChild(newli);
}
listtrigger.parentNode.insertBefore(newol,listtrigger.nextSibling);
return false;
}
}
window.onload=makelists;
Which is not really up-to-date JS (not using addEvent and so on, but
does the trick).
More:
http://www.onlinetools.org/articles/unobtrusivejavascript/
http://www.wait-till-i.com/index.php?p=104
--
Chris Heilmann
Blog: http://www.wait-till-i.com
Writing: http://icant.co.uk/
Binaries: http://www.onlinetools.org/
More information about the thelist
mailing list