views:

45

answers:

2

Hi all, I have a jsp and a js files. I would like to pass arrays from the jsp to a function in the js file via the onload attribute in the body tag. How can I do that?

For example:

<head>
<script language="javascript" type="text/javascript">
        var indexNames  = ['chIndex', 'recordIndex'];
        var indexLocation = [0, 1];
    </script>
</head>
<body onload="addRowHandlers('row', 2, $indexNames, $indexLocation)">

The output is not correct and I think $indexNames and $indexLocation are not the right way to pass the arrays.

Of course, in this case, I can separate the array values into multiple parameters. I am just want to make the javascript function more general. Thanks in advance.

Kenneth

A: 

Something like

<head>
<script language="javascript" type="text/javascript">
        var indexNames  = ['chIndex', 'recordIndex'];
        var indexLocation = [0, 1];
        window.onload =function() {
            addRowHandlers('row', 2, indexNames, indexLocation);
        }
    </script>
</head>
Redlab
My problem was adding the $ to the variables. Thanks.
Kenneth
A: 

hm.i don't know jsp but your example don't work because its javascript. Аnd in onload function js machine don't know what is $indexNames and $indexLocation variable. If you want just to pass arrays in function:

<body onload="addRowHandlers('row', 2, indexNames, indexLocation)">
Falcon
It works. Thanks.
Kenneth