Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 31st, 2005, 10:33 PM
lch lch is offline
Authorized User
 
Join Date: Jan 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default can get an array which in the jsp ???

i have 2 file: jsp and js !!!

now i want pass an array which in the jsp to another file : js file

how can i do it ???

can u give me some links or some source code as the references????

thx

 
Old February 1st, 2005, 01:13 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii lch

 Two ways to do the thing
1)for that u need to assign values at the runtime.
  like
   <script>//define javascript array
             var arr=new Array()
            //assign values to this array
             <% for(i=0;i<=10;i++) %>
              arr[<%=i%>]=<%=jsparray[i]%>
       </script>
2)alternative apporach is that make a combined(join) values of all the jsparray element separated by "~" and pass it to the javascript function ,now javascript function split that value on the "~" basis and that returns the array.

Note-it's not possible to pass the serverside array to the client side javascript function ,so you will have only two approaches.
If there is any other method then let me know.
Hope this will help you


Cheers :)

vinod
 
Old February 1st, 2005, 01:52 AM
lch lch is offline
Authorized User
 
Join Date: Jan 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thx !!! i am grateful to ur helping!!!

i think i need to explain clearly to u all !!1

now i have 2 files: middle.jsp and body.js

in the middle.jsp

<%
Collection result = menuManager.getUserRoleMenu(webSessionUser.getGnus erId());

String menuname[]=new String[200];
int menucounter=0;
Iterator vi = result.iterator();
while(vi.hasNext())
{
HashMap hm=(HashMap)vi.next();
menuname[menucounter]=hm.toString();
menucounter++;
}
%>
<html>
<body>
....

the other one is the body.js ! it is the collection of the methods !!!

i want to pass the string array:menuname to the body.js ???
so ...what can i do ???


now ....my senior advise me like below:
use the form to pass the value !!

<script language="javascript">
function djfkd()
{
var abc=documen.form0.(hidden name).value;
}
</script>
<form name=form0>
<input type=hidden name=??? value="value in jsp">
</form>


dear vinod yadad1919, can u explain again and clearly for my case ??? and i dun know the second method you mention !!!!

thx

regards,
lau chun hui!!!

u also can add me in ur yahoo messenger , my account: [email protected]

 
Old February 1st, 2005, 01:57 AM
lch lch is offline
Authorized User
 
Join Date: Jan 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

the main problem for me ...is need get the value from the jsp to the js!!!!

how to initiate in the jsp and js ???

my another senior say ...cookie also is a good method too !!! but i fail to get it !!! cookie is a good method for solving my problem ???



 
Old February 1st, 2005, 02:04 AM
lch lch is offline
Authorized User
 
Join Date: Jan 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i am a freshgraduate!!!!
and i just start my job for 2 months!!!!

i am very tire for my life !!! working life == boring life !!!!

where can i get the joy in the programmer life???

sleeping(6hrs)+working(10-12hrs)+other(remaining hrs)......it make me crazy!!!

sorry ..i should not complain about my personal life in this forum !!!!


 
Old February 1st, 2005, 03:03 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hiii Ich !!!

Life is very cool to enjoy lets make it simple :)
I am also a new student in programming

copy this code on new jsp page
and run it,please import all the required class.


<script language="javascript">
function ShowValue(arrvalues)
{
myarray=arrvalues.split("~") //here menuname(==myarray) will be actual Array that you want to pass
 //since we can not pass directly array to the client side variable

 for(i=0;i<myarray.length-1;i++)
 {
 alert(myarray[i])
 }
}
</script>
<%
Collection result = menuManager.getUserRoleMenu(webSessionUser.getGnus erId());

String str=""
Iterator vi = result.iterator();
while(vi.hasNext())
{
HashMap hm=(HashMap)vi.next();
str=str+hm.toString()+"~";
}
%>

<script>
ShowValue('<%=str%>');
</script>


Hope this will help you

Cheers :)

vinod
 
Old February 1st, 2005, 05:09 AM
lch lch is offline
Authorized User
 
Join Date: Jan 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

dear vinod,
sorry , my pc got the problem just now .........

so ..i cant online

well , u look an expert in programming !!!

ok , i am trying ur method , i need about 30min to test ..bcos ...i need to repair my pc

c u later

 
Old February 1st, 2005, 05:44 AM
lch lch is offline
Authorized User
 
Join Date: Jan 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

dear vinod,

i have read ur code already, and i have tested it ....

now i have 2 questions:
1. if use the "alert" , it will pop- up the message , but i dun want the message! must use the "alert" to pass the value from jsp to js ?? as i know, "alert" 's function just pop up the message only , not for the value passing!!!or u just want to show me the content of the string array :) hehehe!!

2.in the body.js , it is the "destination" of the value passing !! how can i get and store the string ?? or i can use the "myarray" directly in the body.js!! how to initiate in the body.js???

sorry , i just touch the javascript less than 1 month ...so, it is strange to me !!! i am doing the java application!!! i never touch the javascript before !!!

thx for ur helping !!!

can u add me in ur yahoo messenger ??? i am a Malaysian !!
my email: [email protected]







 
Old February 1st, 2005, 09:17 PM
lch lch is offline
Authorized User
 
Join Date: Jan 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

vinod, i cant send the mail to u bcos ur mail box is the invalid ???

can u give me another mail box??

my mail box:[email protected]

i format my pc last night i think my pc got virus infected the therefore i cant online suddenly

now i think my oc is ok , i hope you wont angry at me !!!

thx ,
regards
lau chun hui


 
Old February 1st, 2005, 11:14 PM
lch lch is offline
Authorized User
 
Join Date: Jan 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

someone can give me more advice to solve this problem ?????

i have 2 file: jsp and js
i want to pass an array from jsp to js
and store the array in the js !!!!!








Similar Threads
Thread Thread Starter Forum Replies Last Post
display byte array of pdf in jsp mahendra.w JSP Basics 2 September 23rd, 2007 11:23 PM
display byte array of jpeg in jsp mahendra.w JSP Basics 1 September 4th, 2007 06:53 AM
print array in jsp yubaraj JSP Basics 0 March 27th, 2007 02:05 AM
getting array value in jsp krishnamoorthymca HTML Code Clinic 0 December 19th, 2006 02:03 AM
how to pass an array in jsp to other js? lch Javascript 5 April 18th, 2006 06:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.