You can send objects to JavaScript functions the same way as constants. To reference objects that are not in a form, you can give them and ID.
Element:
<div id="myelement">Hello</div>
Code:
// function
function jsfunc(variabelname)
{
// dosomething with variabelname
}
// call function with reference to object
jsfunc( document.getElementById("myelement") );
You can also have a function without predefined parameters and access whatever is sent to the function via arguments.
Example:
function jsfunc()
{
var output = "";
var args = arguments;
for(var i = 0, len = args.length; i < len; i++) // loop through all arguments
{
var arg = args[i]; // reference the argument directly
output += i + ": "; // add index number
if (arg == null)
{
output += "null"; // arg is null
} else {
output += typeof(arg) + ", "; // adds type of argument
if (typeof(arg) == "string" || typeof(arg) == "number")
{
// argument is a string og number, which can be easily output
output += arg;
} else if (typeof(arg) == "object") {
// it is an object
if (arg.tagName)
{
// the object has a tagname which means it's an HTML element
output += arg.tagName;
} else {
// object but not HTML element, our array
output += "array, " + arg.firstname;
}
}
}
output += "\n"; // add new line
}
alert(output);
}
jsfunc(
"a" /* type: string */
, 5 /* type: number */
, document.getElementById("txtFirstName") /* type object, has tagName INPUT */
, document.getElementById("ElementThatDoesNotExists") /* type NULL */
, { "firstname" : "john", "lastname" : "smith" } /* type object, no tagname */
);
Output:
0: string, a
1: number, 5
2: object, INPUT
3: null
4: object, array, john
executeSigning(param1, param2, ...)? Javascript supports optional parameters so haveexecuteSigningaccept every prefetched value it might use, but only pass in parameters the form "knows" about.field_onChangewhich you would map the respective handler to. Then in yourfield_onChangemethod make a call toexecuteSigning. I prefer this way because it makes it easier to view/debug JS as everything is in one place and you don't have to view each handler in CRM.