By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,621 Members | 1,775 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,621 IT Pros & Developers. It's quick & easy.

Passing parameters from JSP to JavaScript

P: n/a
Hi!

I have a JavaScript function that receives an Array with words. This
Array can be gotten from a query to a DB using JSP.

The JavaScript function is executed when onFocus event occurs:
<input type='text' onFocus='myFunction(this.event, myArray);' />

myArray is declared as:
<script>
var myArray = new Array('j'habite', 'tu habites', 'il habite');
</script>

I want to tell javascript:
var myArray = myJSPArray;
Where myJSPArray is declared some where in the JSP document.

Is it possible? If so, how can I do it?
TIA!
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Omar" <ro*****@yahoo.com> wrote in message
news:8b**************************@posting.google.c om...
Hi!

I have a JavaScript function that receives an Array with words. This
Array can be gotten from a query to a DB using JSP.

The JavaScript function is executed when onFocus event occurs:
<input type='text' onFocus='myFunction(this.event, myArray);' />

myArray is declared as:
<script>
var myArray = new Array('j'habite', 'tu habites', 'il habite');
</script>

I want to tell javascript:
var myArray = myJSPArray;
Where myJSPArray is declared some where in the JSP document.

Is it possible? If so, how can I do it?
TIA!


No, you'll need to create the array dynamically in the jsp code in js for
the other js to access it.

--
Tom Dyess
OraclePower.com
Jul 23 '05 #2

P: n/a
Omar wrote:
Hi!

I have a JavaScript function that receives an Array with words. This
Array can be gotten from a query to a DB using JSP.

The JavaScript function is executed when onFocus event occurs:
<input type='text' onFocus='myFunction(this.event, myArray);' />

myArray is declared as:
<script>
var myArray = new Array('j'habite', 'tu habites', 'il habite');
</script>

I want to tell javascript:
var myArray = myJSPArray;
Where myJSPArray is declared some where in the JSP document.

Is it possible? If so, how can I do it?
TIA!


You can tell JavaScript anything you want - but in the end, it has no
knowledge of what goes on at the server, it just processes whatever you
load into the (local) programming environment. This:

var myArray = myJSPArray;

....'tells' JS to set a reference at variable myArray pointing to
something at variable myJSPArray...if there's a JS array there, fine,
although the utility of the reference is unclear. As mentioned, there's
no point in downloading jsp code to the JavaScript engine, which
doesn't speak it.

This looks wrong:

onFocus='myFunction(this.event, myArray);

You pass a handable Event object inside an HTML event handler with the
local variable *event*. 'this' refers to the Input object in this
context.

If 'myArray' is global - not necessarily the best thing - you don't
need to pass it anyway, as it'll be visible to the function as well.

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.