Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-06-2011, 03:30 PM   PM User | #1
chittivenureddy
New to the CF scene

 
Join Date: Jul 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
chittivenureddy is an unknown quantity at this point
how to stop the eval sorting in IE9

in IE9 Browser list of country names sorting on keys.
we are using Ajax
javascript:
Code:
var data= remoteRequest(url);
the data like
Code:
data={" 11":"Australia"," 14":"Bermuda"," CAN":"Canada"," 12":"France"," 15":"Germany"," IND":"India"," 16":"Russia"," 13":"South Africa"," 10":"UK"," USA":"United States"}
name_set= eval('('+data+')');
it fine in all browser
the array like
Code:
name_set[11]=Australia
name_set[14]=Bermuda
name_set[CAN]=Canada
name_set[12]=France
name_set[15]=Germany
name_set[IND]=India
name_set[16]=Russia
name_set[13]=South Africa
name_set[10]=UK
name_set[USA]=United States
but in the IE9 browser array keys sorting as like.
Code:
name_set[10]=UK
name_set[11]=Australia
name_set[12]=France
name_set[13]=South Africa
name_set[14]=Bermuda
name_set[15]=Germany
name_set[16]=Russia
name_set[CAN]=Canada
name_set[IND]=India
name_set[USA]=United States
so please help me, how to stop the array sorting in IE9.

thanks in Advance,
Venu

Last edited by Kor; 07-06-2011 at 03:50 PM.. Reason: wrap the code [code][/code]
chittivenureddy is offline   Reply With Quote
Old 07-06-2011, 03:41 PM   PM User | #2
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
What you have there is an Object (that means an unsorted, unordered list) not an Array (which is an ordered list).

See the difference:
http://json.org

As long as you are dealing with an object, it does not matter too much in which order the pairs property:value are arranged, because you can not circle through them using and indent. An Object has no length.

But if, for a reason or another, you need that pairs to be sorted upon the value, not upon the key (property) why don't you sort them using a sorting algorithm? Do you need such a code?
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

Last edited by Kor; 07-06-2011 at 03:48 PM..
Kor is offline   Reply With Quote
Old 07-06-2011, 03:57 PM   PM User | #3
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
By the way: I can not confirm that "sorting" you are talking about. In my IE9 there is no such a "sorting".

And your data should look as a string (see the blue quotes), like:
Code:
var data='{" 11":"Australia"," 14":"Bermuda"," CAN":"Canada"," 12":"France"," 15":"Germany"," IND":"India"," 16":"Russia"," 13":"South Africa"," 10":"UK"," USA":"United States"}';
otherwise what's the point of evaluating it? The way you have written it, there is straight a JSON object.
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

Last edited by Kor; 07-06-2011 at 04:03 PM..
Kor is offline   Reply With Quote
Old 10-27-2011, 01:52 PM   PM User | #4
bhaskar9
New to the CF scene

 
Join Date: Oct 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
bhaskar9 is an unknown quantity at this point
Smile Hi

Hi Venu Did you find the solution? Please let me know

Thanks,
Bhaskar
bhaskar9 is offline   Reply With Quote
Reply

Bookmarks

Tags
ajax, array, eval, javascript, parse

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:12 AM.


Advertisement
Log in to turn off these ads.