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>

Its working fine for me, no reload at all

Its working fine for me, no reload at all

thank for reply network 18, tell me please, which of browsers did you use? I use Opera 10.01, Firefox 3.5.5, Chrome 3.0.195 and Internet Explorer 6.0.29.
1. I open the page, first alert(with content of selection var) shows
2. on OK click browser shows next alert(page is loaded).
3. I click on X for ex. over "text 2"
4. alert - 1:text1,3:text3,
5. clicking OK alert - "loaded"

5th point means for me, browser reloaded page, and doesn't display new content (without text2).
When I try this on IE of version I've written it crashes with close IE application window.

So please which of browsers do you use?

my stupidity. i've used <a href="" in code and this causes reloading page after onclick event, working is <a href="#" or just using <span, or ... element instead of <a
thanks...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.