View Single Post
12-29-2006, 04:18 PM
#7
Wildhoney is offline Wildhoney
Wildhoney's Avatar
Status: Request a custom title
Join date: Feb 2006
Location: Nottingham
Expertise:
Software:
 
Posts: 1,648
iTrader: 18 / 95%
 

Wildhoney is on a distinguished road

Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney

  Old

You should really have a fall back plan in place for if JavaScript is disabled. The best and easiest way to do this is target the relevant event property (onClick) and place Salathe's code onto the button element dynamically, thus if JS is disabled, it'll cruise past it. Ideally to a standard HTML page where you can confirm the deletion.

Code:
<form action="Test/">
	<input type="submit" id="elementName" />
</form>

<script type="text/javascript">

	addEvent(window, 'load', initFunc, false);

	function addEvent(element, eventType, callFunction, useCapture) 
	{
		if(element.addEventListener)
			element.addEventListener(eventType, callFunction, useCapture);
		else if(element.attachEvent)
			element.attachEvent('on'+eventType, callFunction);	
	}

	function initFunc()
	{
		element = document.getElementById('elementName');
		element.onclick = function() { return doConfirm(); };
	}

	function doConfirm()
	{
		var pConfirm = confirm('Delete?');
		if (pConfirm)
			return true;
		return false;
	}

</script>