Problem in providing a string to the JavaScript

by Nishant Bhargava » Fri, 19 Nov 2010 13:24:33 GMT


Sponsored Links
 I am trying to pass an array from Java to JavaScript by converting the
array into a string with the help of delimiter and later splitting in
JavaScript with the split function in JavaScript. Now the problem
arrives if I display String in the form of alert the String is coming
in the JavaScript and is displaying the right output which I want but
the split function doesn't work here for unknown reason but the same
function works if I give the String for same name with the same type
of values defined in the code. The problem is in JavaScript for sure
as the string I am fetching from is being displayed in alert. Please
suggest something, I worked on the problem on emulator only.


This is the function in JavaScript
                function load()
                {
                //var stringFromJava =  
"Nishant|Amit|Ankit|Ashok|Working|Ishaan|
Hallelujah|Floor|Haroon|Fish|Wasim|";
                var stringFromJava = window.cname;
                var names = stringFromJava.split("|");
                sortnames(names);

                }

--



Re: Problem in providing a string to the JavaScript

by Brad Gies » Sat, 20 Nov 2010 01:24:50 GMT


 I don't really fully understand what problem you are having.... Can you 
show an example of what's it's doing... and what you want it to do?


The code you sent looks fine... except that the last string after you 
split the string will be an empty string because you have a "|" at the 
end of the string.


Are you sure "window.cname" is passing what you think it is? Have you 
debugged it and checked to see exactly what you are getting?


Sincerely,

Brad Gies
-----------------------------------------------------------------------
Bistro Bot - Bistro Blurb
 http://bgies.com              http://nocrappyapps.com 
 http://bistroblurb.com        http://forcethetruth.com 
 http://ihottonight.com 
-----------------------------------------------------------------------
Everything in moderation, including abstinence (paraphrased)

Every person is born with a brain... Those who use it well are the successful 
happy ones - Brad Gies

Adversity can make or break you... It's your choice... Choose wisely - Brad Gies

Never doubt that a small group of thoughtful, committed people can
change the world. Indeed. It is the only thing that ever has - Margaret Mead




I am trying to pass an array from Java to JavaScript by converting the array into a string with the help of delimiter and later splitting in JavaScript with the split function in JavaScript. Now the problem arrives if I display String in the form of alert the String is coming in the JavaScript and is displaying the right output which I want but the split function doesn't work here for unknown reason but the same function works if I give the String for same name with the same type of values defined in the code. The problem is in JavaScript for sure as the string I am fetching from is being displayed in alert. Please suggest something, I worked on the problem on emulator only. This is the function in JavaScript function load() { //var stringFromJava = "Nishant|Amit|Ankit|Ashok|Working|Ishaan| Hallelujah|Floor|Haroon|Fish|Wasim|"; var stringFromJava = window.cname; var names = stringFromJava.split("|"); sortnames(names); }
--


Sponsored Links


Re: Problem in providing a string to the JavaScript

by Frank Weiss » Sat, 20 Nov 2010 11:37:01 GMT


 This sounds a bit like the problem of trying to match "|" in a regular
expression (regex). But I can't really tell that the split method is
thinking that its parameter is a regex instead of simple a string. Try "\\|"
and see if that fixes it.

-- 



Re: Problem in providing a string to the JavaScript

by nubh bhargava » Mon, 22 Nov 2010 13:12:53 GMT


 Ya, that's what really makes me worry. I get the string as output when I
provide an alert and when I pass the string which I have commented in the
above code a specific function the code works fine. Just don't understand
the problem why its not showing the output when I pass the string from Java.
For a reason I thought it would be that the string is not coming but strange
thing happened when I display it as alert. The string is coming the way I
want. But its not going in the split command. Tried few cases in which I can
get the output but all in vain. Can you suggest any other way to pass the
array into JavaScript. If there please let me know the code. So I can
improve in this example.

Thanks in Advance and for the kind help and support.
Nishant Bhargava

-- 



Re: Problem in providing a string to the JavaScript

by nubh bhargava » Mon, 22 Nov 2010 14:42:56 GMT


 Guys, I am able to do it. By converting the value to String which I am
fetching from Java. The value was coming in the alert which was strange
earlier.

Thanks for helping anyway.

Nishant

-- 



Other Threads

1. Install Android on a Wondows Mobile device.

hi All,

how can I install Android on a Windows mobile device???

where can I find the installation file???

is there any userguide to install it???

thanks

Vit

--~--~---------~--~----~------------~-------~--~----~

2. how to pluging our own window manager

hi

I was going through the window manager of android. I wonder if is it
possible to replace this window manger with out own window manger. Is
this supported? what depencies are there for this?

please answer this question if anybody knows
thanks in advance
NASAM

--~--~---------~--~----~------------~-------~--~----~

3. How can I install my own Android program to the ported Android platform ?

4. Window manager for Android

5. antialiasing on an overlay?

6. Persisting Intents to Database

7. Using XPath libraries in Android