hi friends, i try to make some selector of items placed in <div>, and click on some of items should delete one by changing innerHTML of <div>. delete works, but after delete html page reloads. i suppose its because element, originator, calling delete function exist at time of calling, but after delete no more exists and javascript engine forces page reload instead of error. is there any way to solve this behaviour?
thanks a lot, have a good times
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<script type="text/javascript">
<!--
selection = "1:text1,2:text2,3:text3,"
function getelebyid(id)
{
if(document.layers) //NN4+
obj = document.layers[id];
else if(document.getElementById) //gecko(NN6) + IE 5+
obj = document.getElementById(id);
else if(document.all) // IE 4
obj = document.all[id];
return obj;
}
function showselected()
{
alert(selection)
tmp = selection
html = '<table cellpadding=3><tr>'
while (1==1)
{
pos = tmp.indexOf(",")
if (pos < 0)
break
pos2 = tmp.indexOf(":")
id = tmp.substring(0,pos2)
text = tmp.substring(pos2 + 1, pos)
html = html + '<td><a href="" onclick="removefromselection(\'' + id + '\');">X</a><br><b>' + text + '</b></td>'
tmp = tmp.substring(pos + 1)
}
html = html + '</tr></table>'
getelebyid('iddivselection').innerHTML = html
return 0
}
function removefromselection(idtoremove)
{
tmp = selection
newselection = ''
while (1==1)
{
pos = tmp.indexOf(",")
if (pos < 0)
break
pos2 = tmp.indexOf(":")
id = tmp.substring(0,pos2)
text = tmp.substring(pos2 + 1, pos)
if (id != idtoremove)
newselection = newselection + id + ":" + text + ","
tmp = tmp.substring(pos + 1)
}
selection = newselection
showselected()
return 0
}
// -->
</script>
</head>
<body onload=alert("loaded")>
<div id=iddivselection></div>
</body>
<script type="text/javascript">
<!--
showselected();
// -->
</script>
</html>