473,386 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Passing parameters from JSP to JavaScript

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
2 8167
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: timwap | last post by:
I hava a Java Applet that produces a DTMF tone at a certain time of day. There are 4 parameters to the Applet, they are hour = Hour of triggered event 00~23 min = minute of triggered event 00~59...
7
by: Pavils Jurjans | last post by:
Hallo, I have been programming for restricted environments where Internet Explorer is a standard, so I haven't stumbled upon this problem until now, when I need to write a DOM-compatible code. ...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
2
by: John | last post by:
Hi all, I had an .aspx page which would be opened modally from a previous page and just prior to the parent opening the aspx page, a javascript would run and pass parameters like...
1
by: Paul D. Fox | last post by:
I'm trying to launch a Child Window from a hyperlink on a Datagrid and have it recieve multiple values from the Parent Window. Upon recieving the values in the Child Window, I need to access them...
6
by: ged | last post by:
Hi, i am a oo (c#) programmer, and have not used javascript for a while and i cant work out how javascript manages its references. Object References work for simple stuff, but once i have an...
4
by: Nathan Sokalski | last post by:
I am a beginner with AJAX, and have managed to learn how to use it when passing single parameters, but I want to return more than one value to the client-side JavaScript function that displays it....
4
by: simon | last post by:
hi, I would like to separate my javascript completely from my xhtml. in the end there should be only <script type="text/javascript" src="javalib.js"></script> in the head-tag to my javascript....
3
by: JJ | last post by:
I am using a handler (processImage.ashx) to display an image. The image is displayed according to parameters passed in the querystring. The handerl is called via some clientside javascript. I...
3
by: pavanip | last post by:
Hi, I have written the code for display popup window using javascript in button onclient click event. <asp:Button ID="Button1" runat="server" Style="position: static"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.