JavaScript - Outcome functionality extension

From All n One's bxp software Wixi

Jump to: navigation, search

In bxp, there is no direct way to add onchange functionality to an outcome drop down list. It is however possible to extend the functionality of any drop down element with custom JavaScript.

The following can be added to your onLoad of the form.


// Based on http://stackoverflow.com/questions/6831528/add-a-second-onchange-event
//===================================================================
function fn_General_onChange_AppendFunction ( strObjectName ) { 

	//If that select exists
	if (document.getElementById(strObjectName)) {

	//Get the object
		var objObject = document.getElementById(strObjectName);
		
		//Modern browsers
		if (objObject.addEventListener) { 
			objObject.addEventListener("change", function(e){ 
				e = e || event;
				//Calls your custom function
				fn_MyCustomFunction();
			}, false);
		} 
		// Older browsers (IE 5 - 8)
		else if (objObject.attachevent) { 
			objObject.attachEvent("onchange", function(e){
				e = e || event;
				//Calls your custom function
				fn_MyCustomFunction();
			});
		} 
	}
} 
//===================================================================
function fn_MyCustomFunction() {

	//Gets the current outcome chosen
	var strContact_Outcome == document.getElementById ('strContact_Outcome').value;
	
	//if this is the outcome you want to do something with.
	if ( strContact_Outcome == 'Your Outcome' ) {
		//Perform some action
	}

}
//===================================================================
//Now kick it off
fn_General_onChange_AppendFunction ( 'strContact_Outcome' );
//===================================================================