Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

Assigning JavaScript variable to a Java String variable

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
NoelleBlaney
Asked:
NoelleBlaney
  • 4
  • 2
  • 2
  • +1
1 Solution
 
CJ_SCommented:
var content=two_dim[0][6]+"";
0
 
knightEknightCommented:
or:

String content = String.valueOf(two_dim[0][6]);
0
 
dalarcongCommented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
NoelleBlaneyAuthor Commented:
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
 
CJ_SCommented:
Can you please finalize this question then? Either delete or accept any of the above, correct, answers.

CJ
0
 
NoelleBlaneyAuthor Commented:
None of the above were correct so what do I do in this situation - can't accept any of them as the answer!!!
0
 
CJ_SCommented:
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
 
CJ_SCommented:
Thank you for finalizing!
0
 
knightEknightCommented:
NB, points should have gone to CJ for answering first ... his answer is as correct as mine.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now