Difference between revisions of "JavaScript - Outcome functionality extension"
From All n One's bxp software Wixi
Philip Lacey (talk | contribs) (Created page with "In BeX, 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 cu...") |
Philip Lacey (talk | contribs) |
||
| Line 53: | Line 53: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| + | |||
| + | |||
| + | |||
| + | [[Category:Module Specific:Form Management]] | ||
| + | [[Category:Topic:JavaScript]] | ||
Latest revision as of 20:26, 9 November 2014
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' );
//===================================================================