Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 9th, 2003, 04:59 PM
Authorized User
 
Join Date: Oct 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using JScript with VBScript

All,

This is rather a complex question... I am hoping someone can help me... I have written a recursive function in VBScript that builds a dynamic tree from our SQL database. I don't know JavaScript very well, so I've downloaded code to help in building a collapsible tree structure without refreshing the page. I'm having a little trouble figuring out how to port my nicely formed tree into JavaScript.

Basically, the JS code I'm using makes use of functions and methods so that the tree is built similar to this:

level1ID = theMenu.addEntry(-1, "Folder1");
level2ID = theMenu.addChild(level1ID, "ChildObject1");
level2ID = theMenu.addEntry (level2ID, "ChildObject2");
level2ID = theMenu.addEntry(level2ID, "Folder");
level3ID = theMenu.addChild(level2ID, "Document");

I'm not sure how best to interface my recursive code with the above code to build a dynamic, data-driven solution.

Any ideas?


 
Old October 9th, 2003, 05:00 PM
Authorized User
 
Join Date: Oct 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If it means anything to anyone, I'm using "Joust" as my tree solution.

I'll also freely send my VBScript to anyone who's willing to help.

 
Old October 10th, 2003, 04:52 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

When you say VBScript and JavaScript do you really mean that or do you mean server side VBscript and client side JavaScript?
If you could post a code fragment or two to start the ball rolling...
For example to transfer server side variables to client, if you have a variable sCustomerSurnameVBS in your server side VBScript and you want to manipulate it client side:
Code:
var sCustomerJS = "<% = sCustomerNameVBS %>";
You have to watch embedded quotes etc.


--

Joe
 
Old October 10th, 2003, 09:30 AM
Authorized User
 
Join Date: Oct 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It doesn't specify a "runat" parameter, so I don't know if the JavaScript runs server side or client side. From the way I understand it, it would have to be client side given that it allows collapsing and expanding of the tree without refreshing the page. But I don't know JavaScript well enough to know what difference it makes.

All told, this is over 1000 lines of code, so I'm not sure which lines would be more meaningful than the ones I have already posted. Unfortunately, it's not nearly as simple as pasting a few variables into the JavaScript code because the tree must be 100% dynamic in its depth, number of nodes, etcetera.

I'm toying with the idea of building arrays of some sort and trying to loop through them in JavaScript code, but I don't really know how that's going to work yet. You have to use an "AddChild" method for the FIRST entry on a particular level and "AddEntry" methods thereafter, so somehow I'm going to have to track whether each possible level has a node already when I need to populate a node on that level.

Its looking to me like the recursion on the VBScript side may have been a waste of time. I wish there was a way to neatly intertwine the two coding structures so I could add records within the JavaScript function INSIDE the VBScript loops. But it's sounding like there's no good way to do that... ?
 
Old October 13th, 2003, 10:07 AM
Authorized User
 
Join Date: Oct 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

All,

Just FYI - I ended up using a VBScript code tag inside the JavaScript function to build the code dynamically. This is the very first thing I tried and I received an error to the effect of "cannot place one code block inside of another", but a fellow programmer here at M2M told me to use this solution and wrote an example that worked.

I honestly have no idea what the difference was... But building the code dynamically simplified the process greatly. (See below)

<%
Response.Write("level"& arrJSLevel(i) &"ID = theMenu.addEntry(level"& arrJSLevel(i) &"ID, """ & arrJSValueOne(i) & """, """& arrJSValueTwo(i) &""", """& arrJSValueThree(i) &""", """& arrJSValueFour(i) &""");" & vbCrLf)
%>





Similar Threads
Thread Thread Starter Forum Replies Last Post
JScript DumAss HTML Code Clinic 1 August 25th, 2004 02:46 AM
submit using jscript alyeng2000 ASP.NET 1.0 and 1.1 Basics 3 June 14th, 2004 07:38 AM
how to debug jscript alyeng2000 ASP.NET 1.x and 2.0 Application Design 4 May 22nd, 2004 05:13 AM
JScript Des67 Javascript 1 July 28th, 2003 05:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.