473,732 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 13391
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("<S CRIPT language=javasc ript>");
out.println("fu nction 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("<S CRIPT language=javasc ript>");
out.println("fu nction 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(jav aArray.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
6790
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 stuck: I have page of results obtained from a MySQL query presented as a table (the first column having checkboxes for each of the rows in the table, and all having the name "seqs"). I have set up a javascript (connected to a "toggle all" checkbox)...
2
6444
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
5570
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
2508
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++) { items = "item" + (i + 1);
3
1681
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
1178
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 Javascript handler. I can pass a string but passing an array doesn't seem to work. John Dalberg
4
4339
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 "selectedValues" from next page for php variable this is my javascript code saved on "sendValue.js" file, <script> function updateRecordEntry(requestValue){
4
2377
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 store the textbox values into some array and want to pass the array as an value of hidden variable <% int i =0; String arr_TextValues = new String; String arr_ChkValues = new String;
9
30131
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 and I can't get this issue out of my head !!!! So I'm obviously missing something really simple and can't see it or it can't be done with my limited knowledge. I know that I can use a cookie to store the array as string - I have this working but...
0
8946
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
8774
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9307
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
8186
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
6735
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
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3261
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
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
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.