MediaWiki Developer's Handbook/Add JavaScript/Hiding unwanted information on the deletion form

From Wikibooks, open books for an open world
Jump to: navigation, search
function cleanDeleteReason(){								//Declare the function and its parameters
	var wpReason = document.getElementById("wpReason");				//declare a variable and set its value
	if (!wpReason) return;								//if there's no such thing (i.e. the
											//previous line didn't find an
											//element with that id) then return
	var regexp = /(content was|page was empty|content before blanking was)/i;	//create a regexp object which
											//matches the default delete reasons
	if (regexp.test(wpReason.value)){	//if the regexp object we created tests true against the value
						//of wpReason (which is a DOM element)...
		wpReason.value = "";		//then set the value of wpReason to an empty string
	}
}
if (wgAction == 'delete') addOnloadHook(cleanDeleteReason);	//if the current action is deleting, then hook onto page load
								//and run the cleanDeleteReason function