0

hi

i'm using a jQuery Inline Modal Window. the code for it can be found here

http://www.sohtanaka.com/web-design/inline-modal-window-w-css-and-jquery/

i currently have an array within a function in javascript. when i click on the appropriate link for the inline modal, the inline modal window appears.

my function looks something like this

function match_all_groups(){

    var pop_up_status;
    var match_groups = new Array();
    var match_groups_count = 0;

    $(document).ready(function(){

    for ($i = 0; $i < all_og_count_js; $i++){

    if ($i == 125)
        {
            $i = $i + 1;
        }
    if ($i == 130)
        {
            $i = $i + 1;
        }
    if ($i == 135)
        {
            $i = $i + 1;
        }

    if(($('#edit-title').val().search(all_og_groups_name_js[$i]) != -1) || ($('#edit-body').val().search(all_og_groups_name_js[$i]) != -1)){
    pop_up_status = true;
    break;
    }
    else{
    pop_up_status = false;
    }

    }

    });


    for ($i = 0; $i < all_og_count_js; $i++){

    if ($i == 125)
        {
            $i = $i + 1;
        }
    if ($i == 130)
        {
            $i = $i + 1;
        }
    if ($i == 135)
        {
            $i = $i + 1;
        }

    if(($('#edit-title').val().search(all_og_groups_name_js[$i]) != -1) || ($('#edit-body').val().search(all_og_groups_name_js[$i]) != -1)){
    match_groups[match_groups_count] = all_og_groups_name_js[$i];
    match_groups_count++;
    }

    }


    if (pop_up_status == true){
        $('a.poplight[href^=#]').click(); //please look at the above link to see how this inline modal window works
    }
    else{
        document.getElementById("node-form").submit();
    }

    }

</script>

i want to receive values from match_groups and display them in my inline modal window. do u know how this can be done?

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by gambit_1607
0

Hi Gambit,

I've never seen $(document).ready(...) inside a function before. Can you explain the reasoning behind that please?

To answer your question, there are two ways to access your data:

  1. Declare the member, var match_groups = [] , in an outer namespace, (eg. as a global, though this should be avoided), then set the member's value(s) within the function. The member is then available to the outer namespace and all its inner namespaces.
  2. Declare the member in the function, and form a "closure" by defining inner function(s) for later execution, typically attached as event handlers.

(1) is the easier to understand and probably right the way ahead for you in this case.

Understanding "scope" is central to good javascript.

Google "javascript scope" for some good discussions.

Airshow

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.