473,780 Members | 2,258 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Converting "[['Main,0,0'],['Options',0,0']]" string to array javascript

9 New Member
Hi all!, I'm creating a app with PHP and MySQL, the system administrator is capable of creating profiles, on each profile we create, we add a custom access menu (a javascript tree view menu), theres a <textarea> where the admin enters the tree array, example:

[
[''Main,0,
['sub1',0,0],
['sub2',0,0]
],
[''Manuals,0,0],
[''whatever,0,0],
[''Options,0,0]
]

I want to create a "preview" button that would open a popup with the preview of the tree.... the script of the pop-up to create the tree preview is:

*if i do this:
Expand|Select|Wrap|Line Numbers
  1.   var arr =[['SAP Introduction',0]];
  2.   var arbol=new tree (arr, TREE_TPL);
  3.  
It Works!

*if i catch the contents of the <textarea> like this:
alert(opener.th edata); //made this to test the input and displays [['SAP Introduction',0]]
Expand|Select|Wrap|Line Numbers
  1.   var arr =opener.thedata;
  2.   var arbol=new tree (arr, TREE_TPL);
  3.  
Did not work

How could i conver the string recieved into an array? it worked using a php variable like this:
[HTML]<script language="JavaS cript">
var test =[<?php echo $database->getTree($sessi on->username);?>];
var arbol=new tree (test, TREE_TPL);
</script>
[/HTML]
Hope you guys can help me!!

Cheers!

gsosa
Nov 2 '07 #1
7 2004
sosamv
9 New Member
The user enter the array on a <textarea> on the following format:

[
[''Main,0,
['sub1',0,0],
['sub2',0,0]
],
[''Manuals,0,0],
[''whatever,0,0],
[''Options,0,0]
]

Theres a "preview" link that will open a pop-up that uses the users array (entered on the textarea) to create the tree with the following javascript code:

var arbol=new tree (info_from_the_ textarea, TREE_TPL);

but this is obviously a string and its not being detected as an array, what can i do? i tried adding square brackets [] on each side of the variable (that worked when pulling the tree from MySQL and PHP).

Please help me hehe.
Thanx in advance
Nov 2 '07 #2
acoder
16,027 Recognized Expert Moderator MVP
There probably is a better solution, but eval should work.
Nov 3 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
Just noticed the double-posted thread on the same topic which I've merged
Nov 3 '07 #4
sosamv
9 New Member
There probably is a better solution, but eval should work.
I just tried eval() and didnt work I tried this
Expand|Select|Wrap|Line Numbers
  1. var input = new Array([string_with_the_array_structure]);
Expand|Select|Wrap|Line Numbers
  1. var input = new Array(eval(string_with_the_array_structure));
any other suggestions??
Nov 5 '07 #5
gits
5,390 Recognized Expert Moderator Expert
hi ...

just try to use eval and remove the new Array instantiation ...

kind regards
Nov 5 '07 #6
sosamv
9 New Member
Great! now it worked!!

Expand|Select|Wrap|Line Numbers
  1. var arbol=new tree (eval(opener.thedata), TREE_TPL);
that was the answer =)

Thanx a lot guys!
Nov 5 '07 #7
acoder
16,027 Recognized Expert Moderator MVP
You're welcome. Post again if you have any more questions which we'll make an attempt at answering.
Nov 6 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
10309
by: Hal Vaughan | last post by:
If I have a byte and I convert it to string (String sData = new String(byte bData), then convert it back (byte bData = sData.getBytes()), will all data be intact, or do Strings have problems with bytes that are not printable characters? I've tested this and it seems to work fine, but I want to make sure there isn't some condition or situation I'm not aware of that could cause problems. I'm doing this because it's easier to do some of my...
5
4473
by: _BNC | last post by:
I've converted " byte" to "byte *" at times, using 'unsafe' and fixed { .... }, but the reverse does not seem to work. In this case, a C++ DLL returns a byte * and a length. What is the best way to convert these to straight C#-compatible straight " byte" arrays? PS: The C++ DLL is actually managed and I have access to the source. Perhaps there is a simpler syntax for doing the conversion there, and returning a C# compatible array...
6
2474
by: Jofio | last post by:
I have a .h (header file) linked using #include<...>. I also have a .cp file which i don't know how to include in the header of my "main" file. I have the following c++ file. The file names are: 1) dArray.h 2) dArray.cp 3) dArrayTest.cpp dArray.h file declares and defines a class called DynamicArray. dArray.cp defines the functions declared as member functions in DynamicArray class in dArray.h. This dArray.h is includded in the
12
7133
nomad
by: nomad | last post by:
Hi everyone; My Class has ended and I was not able to solve this problem in time, and I would still like to solve it. I got these error code. Exception in thread "main" java.lang.NullPointerException at ticketSales.TicketSales.makeEvent(TicketSales.java:185) at ticketSales.TicketInput.main(TicketInput.java:56) Anyway I have several Class This one is called TransAction
2
4734
by: stainless | last post by:
I know this is probably simple but I cannot find a method of converting a date string into a format that matches the DatePicker format in C# eg string "20080131" converted to "31 January 2008" I tried datetime.parseexact but could not find the definition for the appropriate format string. This would be a very useful tool fo me. Any ideas,please?
6
24258
by: Light | last post by:
Hi I m getting this error while i m trying to run my program and i don't understand why that happens. import java.util.*; public class Exercise6 {
3
2587
by: gator6688 | last post by:
import java.text.DecimalFormat; import javax.swing.JOptionPane; public class PayrollSystemTest { public static void main( String args ) { String workerType; String first; String last;
2
3961
by: lilyumestar | last post by:
This project is due by Tuesday and I haven't even gotten half of it done. Can anyone please help me with this Exception error? I've been trying to figure it out for several hours Error Message "Main" Java.lang NullPointerException at Project1.sortingByZipCode<Project1.java:80> at Project1.main<Project1.java:31> Here is the Source Code
3
7659
by: ohadr | last post by:
hi, i get Exception in thread "main" java.lang.NullPointerException when i run my application. the exact error is: "Exception in thread "main" java.lang.NullPointerException at sortmergejoin.MergeJoin.Field(MergeJoin.java:204) at sortmergejoin.MergeJoin.SMJoin(MergeJoin.java:84) at sortmergejoin.MergeJoin.<init>(MergeJoin.java:34) at sortmergejoin.Main.main(Main.java:24) Java Result: 1"
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9931
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6727
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.