All pastes #364653 Raw Edit

Miscellany

public text v1 · immutable
#364653 ·published 2007-02-20 09:10 UTC
rendered paste body
function btnClick(e)
{
	e = getCommonEvent(e || event);
	
	var input, f = e.target.frm;
	
	if ( e.target.getAttribute("id") == "btnDelete" )
		if ( !confirm("Are you sure you want to delete this record from the database?") )
			return( false );
	
	if ( !isDOM && typeof f.onsubmit == "function" )
		if ( !f.onsubmit() )
			return( false );
	
	if ( !f.btnSubmit )
	{
		// so the server knows which button was clicked
		input = document.createElement("INPUT");
		input.type = "hidden";
		input.name = "btnSubmit";
		input.value = e.target.getAttribute("id");
		f.appendChild( input );
	} else if ( f.btnSubmit.getAttribute("type") == "hidden" )
		f.btnSubmit.value = e.target.getAttribute("id");
	
	if ( !isDOM ) f.submit();
}

function bindFormButtons()
{
	var btn, btnType, frm = document.getElementsByTagName("form");
	var i, x, btnLen, frmLen = frm.length;
	
	for (i = 0; i < frmLen; i++)
	{
		buttons = frm[i].getElementsByTagName("button");
		btnLen = buttons.length;
		for (x = 0; x < btnLen; x++)
		{
			buttons[x].frm = frm[i];

			if ( typeof buttons[x].onclick == "function" || ( (btnType = buttons[x].getAttribute("type")) && btnType == "reset" ) )
				continue;
			
			bindEvent(buttons[x], "click", btnClick);
		}
	}
}