So I found an awesome solution to get around needing to use Global variables in jQuery here. Everywhere I say namespace, originally I was going to use a Global var.
However I'm not able to send my namespace variable through a param on a simple click function.
I want to do this because I have these variables that need to be saved and used to create modal windows as well as to let the app know what dynamically created buttons control what modal.
So below is an example of my namespace object where I first create the variables My jQuery namespace object:
$.reg = {
masterRole : " ",
role_ID : " ",
row_Name : " ",
ary_Check_Role : []
};
$(document).ready(function () {
...
As you go through the app the values for those namespace variables get set when you click this button (grabs data from HTML) Variables are set on my roleBtnClicked function
function roleBtnClicked(event){
$.reg.masterRole = $(this).html(); /* Get role name: Actor */
$.reg.role_ID = $(this).attr('role'); /* Get role-1 */
$.reg.rowName = $(this).attr('row'); /* Get row-role-1 */
$.reg.blueBtn = $(this).attr('blue'); /* Get blue-btn-1 */
Now a modal window pops up, after clicking some checkboxes and pushing data into an array, when you click the done button(below) all the variables need to be saved into the namespace vars again.
My done button click Function, where I'm trying to pass my namespace variables via param vars
$(".doneButton").click(
{
param1: $.reg.masterRole,
param2: $.reg.role_ID,
param3: $.reg.rowName,
param4: $.reg.ary_Check_Role
},
doneBtnClicked);
function doneBtnClicked(event){
alert('$.reg.roleName = '+$.reg.roleName);
alert('event.data.param1 = '+event.data.param1);
masterRole= event.data.param1;
role_ID = event.data.param2;
rowName = event.data.param3;
ary_Check_Role = event.data.param4;
Note the 2 Alerts above in the click function, the first one will display the correct value, however the 2nd one doesn't display anything. Also Having a problem getting the Array to come through as well.
So questions: Should I be doing it this way? How do you pass an Array into a jQuery namespace correctly and then get it passed into a click function param?