473,624 Members | 2,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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='myFunc tion(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 8178
"Omar" <ro*****@yahoo. com> wrote in message
news:8b******** *************** ***@posting.goo gle.com...
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='myFunc tion(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='myFunc tion(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='myFunc tion(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
8064
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 sec = Second of triggered event 00~59 tone = DTMF Tone to play 0~9 A~F # & * I now need to write a HTML/JavaScript web page that will enable me to pass these 4 parameters to the applet.
7
49569
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. The question is about best practices for passing parameters to an event function. I have, say, the following HTML:
3
14927
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) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
2
2790
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 mypage.aspx?parm1=a&parm2=b. I would then access the parameters in my code-behind as simple request variables and everything worked fine. I now have to open an .htm file first and inside this htm file is an iframe containing the previous-mentioned page. I...
1
4986
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 in the code-behind so I can render a datagrid in the Child. I've tried just doing another Postback in the child's onLoad event but I get a Javascript error. Is there another way to do this? <%@ Page Language="vb" AutoEventWireup="false"...
6
5577
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 object collection and stanrd using it it starts to fall apart. Clearly there is something about javascript's usage of passing "By ref" that i am not getting. i have had a look on the web and found some examples, but i cant see why my code does not...
4
3833
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. My client-side JavaScript function takes 4 parameters (which are expected to be integers). The idea of passing a single parameter and parsing it on the client has occurred to me, but since I am sure I am not the only person who has situations that...
4
2374
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. Because I want to use some ajax-requests and other javascript-functions on my xhtml, I need to dynamically add event handlers to any possible dom-elements. All solutions I found so fare are for specific, pre-known
3
5782
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 want to send an array of unknown length to the handler. I am not sure whether the querystring is the best place to do this. What's the best way to send an array held in the client side javascript to the handler? Thanks in advance, JJ
3
7704
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" OnClientClick="openwindow()" Text="Execute"/> <script type="text/javascript"> function openwindow() { window.open("AssignedTickets.aspx",'window','width=630,height=620,background=silver,menubar=no, resizable=no') }
0
8231
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8614
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7153
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6107
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2603
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1474
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.