Solved

Assigning JavaScript variable to a Java String variable

Posted on 2002-05-27
9
271 Views
Last Modified: 2008-02-26
I am trying to assign an element of a JavaScript two dimensional array to a Java String variable. The element is a number but I want to assign it as a string but as there's no JavaScript string datatype it seems to cause problems. This variable must be contained in a Java String variable as we are using WebSphere classes and it will not accept it otherwise.

Here is an example of what I'm trying to do:

String content=two_dim[0][6];

two_dim is my JavaScript array.

Any help would be appreciated.
0
Comment
Question by:NoelleBlaney
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 22

Expert Comment

by:CJ_S
ID: 7037707
var content=two_dim[0][6]+"";
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 50 total points
ID: 7039368
or:

String content = String.valueOf(two_dim[0][6]);
0
 

Expert Comment

by:dalarcong
ID: 7041346
Hi Noelle,

I think that's not possible assign Javascript variables to Java variables, cause Java runs on server and Javascript in local. So, you can not exchange values.
In the other way, however, you can assign Java variables to Javascript variables. In JSP files would be like this:
'var a = <%=javaVar%>;'
0
 

Author Comment

by:NoelleBlaney
ID: 7041355
I have since found a way around our problem - as the value we need is in a JavaScript array - and we want to pass it in through a form - I used

var content=two_dim[0][6];

document.forms[0].CatEntryId.value=content


This actually works - but thanks for the suggestions anyway.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Expert Comment

by:CJ_S
ID: 7041484
Can you please finalize this question then? Either delete or accept any of the above, correct, answers.

CJ
0
 

Author Comment

by:NoelleBlaney
ID: 7041501
None of the above were correct so what do I do in this situation - can't accept any of them as the answer!!!
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7041520
They are correct, you just found another way to overcome your problem (with the exact scenario not mentioned in the question). IMHO the answers are correct for the question you gave us.

Personally I don't care much what ever you do. However, if you feel none of the above helped you in any way I suggest you delete this question.

CJ
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7041544
Thank you for finalizing!
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 7041728
NB, points should have gone to CJ for answering first ... his answer is as correct as mine.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now