473,395 Members | 1,468 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,395 software developers and data experts.

Pass a String array in a javascript

Hi,
I am at present working on a jsp page which has a single text field.
Upon entering a value in the field, i am trigerring an onChangeEvent()
which calls a method of javascript. I am also dynamically creating an
array in the jsp page and want to pass this array (by reference) to
the javascript function.
All I want to do in the javascript function is to check whether the
input value matches with any of the array elements. However, i have
not been able to pass the String array in the javascript by reference.
Any help/suggestion would be appreciated.

cheers
Jul 23 '05 #1
4 13355
Sunny wrote:
I am at present working on a jsp page which has a single text field.
Upon entering a value in the field, i am trigerring an onChangeEvent()
which calls a method of javascript. I am also dynamically creating an
array in the jsp page and want to pass this array (by reference) to
the javascript function.
Then you have a lot to learn about the separation of server-side
scripting an client-side scripting. As the two execute at different
times and in different places passing an array by reference is
meaningless.
All I want to do in the javascript function is to check whether the
input value matches with any of the array elements. However, i have
not been able to pass the String array in the javascript by reference.
Any help/suggestion would be appreciated.


(apart from indirect tricks with XMLHTTP requests and the like, which
introduce significant unreliability's) The obvious way of getting a Java
array from a JSP to any script running in the browser based on the HTTP
response sent form the JSP to the browser, is to have the JSP write the
array into its output in the form of a javascript Array literal. Thus
the data becomes available to the script in the browser.

Richard.
Jul 23 '05 #2
Do u mean writing the entire javascript function in jsp scriplet tags?

As in

<% out.println("<SCRIPT language=javascript>");
out.println("function fname(){");
..............
..............
out.println("}</SCRIPT>");
%>

Wont this print the words (between the quotes) on the jsp page?

cheers

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3
Sunil Kamath wrote:
Do u mean writing the entire javascript function
in jsp scriplet tags?

<snip>

Where did I say anything about functions?

Richard.
Jul 23 '05 #4
Sunil Kamath wrote:
Do u mean writing the entire javascript function in jsp scriplet tags?

As in

<% out.println("<SCRIPT language=javascript>");
out.println("function fname(){");
.............
.............
out.println("}</SCRIPT>");
%>
No, as in

%>
<script type="text/javascript>"
function fname()
{
...
}
</script>
<%

of course.
Wont this print the words (between the quotes) on the jsp page?


It will, however you missed the point. Richard meant something like

%>
<script type="text/javascript>"
var jsArray = ["<%
String[] javaArray = {"foo", "bar"};
out.println(javaArray.join("\", \""));
%>"];
</script>
<%

which could generate

<script type="text/javascript>"
var jsArray = ["foo", "bar"];
</script>
HTH

PointedEars
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nath | last post by:
Please help!? I am new to writing html, javascript, pretty new to MySQL but quite proficient at writing Perl and i'm a quick learner. I am building a database driven website and i am a little...
2
by: Augusto Cesar | last post by:
Hello people. How can I Pass ASP Array variable to Javascript; I´m to trying this: <script language="JavaScript"> var x = new Array(10);
6
by: ruca | last post by:
Hi, How can I pass an array string to javascript? I have this: in ASP.NET VB code: -------------------------------------------------------------------- Dim siteName(100) As String
10
by: Sean Dockery | last post by:
I have the following HTML file that I've been using for testing... <html> <head> <script type="text/javascript"> <!-- function handleWindowLoad() { var items = ; for (var i = 0; i < 11; i++)...
3
by: Boki | last post by:
Hi, Could you please advice, can javascript accept this kind of code? function resone(cnt) { alert("document.all.txt_note"+cnt) // cnt is the textbox index
0
by: John Dalberg | last post by:
I have a webpage with an embedded .NET usercontrol. I have an event handler for the user control in the page's Javascript. When the event fires in the user control, I need to pass an array to the...
4
by: IRC | last post by:
hey, i am pretty new on javascript as well as PHP, Hey, anyone can you help me, how to pass the javascript array value to php page......... i want to retrieve the values which are arrayed on...
4
by: akshay01 | last post by:
Hi All, I am using the following code in which i am creating some textboxes and and as the for loop continues the name of the textboxes will also be unique for all the textboxes. now i want to...
9
by: nicnac | last post by:
Hi, I'm self learning javascript - so any pointers are welcomed!! I have an issue passing a form and array from one function to another. I tried many variations ! I can't get this to work...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.