Click to See Complete Forum and Search --> : how 2 create an Object in JavaScript
lirlir
Jul 17th, 2000, 02:38 AM
to create a object in VBScript i write the next code:
<%
set rs = server.CreateObject("ADODB.Recordset");
set OBus =server.CreateObject
("TreeBusiness.clsTreeBusiness");
call OBus.InitializeLogin
("10.10.10.8","project_liron","sa","sa");
%>
how can i do the same in JavaScript ?
Ianpbaker
Jul 17th, 2000, 04:40 AM
Hi Lirlir
Chack out this site. It tells you all about objects in javasvript.
http://wsabstract.com/javatutors/object.shtml
or
http://www.javaworld.com/javaworld/jw-05-1996/jw-05-javascript-2.html
Ian
[Edited by Ianpbaker on 07-17-2000 at 05:43 AM]
lirlir
Jul 17th, 2000, 05:23 AM
Thanks saver !!!
but if u can give me an example.
like in VBS it is: set x= server.createobject
("ADODB.Recordset")
and in JS it is : ???????????????????????
lirlir
Ianpbaker
Jul 17th, 2000, 05:35 AM
If I remember correctly, if you want to use databases that way you need to use pearl/CGI which I don't know. The problem if you could use javascript with databases is that All the js is run client side. So you would need a database on every computer in the same place that was looking at your site. So as you can probably tell it's not worth it if you could do it.
Also, if your fairly happy using ASP, pearl/CGI is basically a different way of having server side script like ASP
Ian
lirlir
Jul 17th, 2000, 05:42 AM
The thing is that I want to create the tree based on a table with the tree properties.(key,parent,caption,link,level,islast{for pages only}).
I already created the tree and the table with the mentioned fields, and a .dll to handle the tree table (the table is on a SQLServer).
So far so good !!! (I hope that u understand me)
I have a few problems :
1. I don’t know if I can use VBS and JS in the same asp/html page.
2. if it isn’t possible than , I don’t know how to create an object on JavaScript
I hope u can help me with my problem.
My version for ix_js : including BuildTree function (JS) and on top of the source code the definitions of the objects.(ADODB,TreeBusiness{my .dll})
The next is placed at the top of the code as VBS :
<%
set rs = server.CreateObject("ADODB.Recordset");
set OBus =server.CreateObject("TreeBusiness.clsTreeBusiness");
call OBus.InitializeLogin("10.10.10.8","project_liron","sa","sa");
%>
The next is placed at the JS Block as JS :
BuildTree("RP",0);function BuildTree(node , level)
{
rs =new OBus.GetNodes("Parent='" & cstr(node) & "'");
if (!(rs.EOF) && !(rs.BOF))
{
while (!(rs.EOF))
{
if (level==0)
{ initTree(rs.fields("Caption"),rs.Fields("NKey"),rs.Fields("Link")); buildTree(rs.Fields("NKey"),level+1); rs.movenext
lastPage("My Helper","c","help.htm"); end_Tree(); }
else
{ if ((level==1) || (level==2)) {
sub_Book(rs.fields("Caption"),rs.Fields("NKey"));
buildTree(rs.Fields("NKey"),level+1);
end_Book();
rs.MoveNext;
} else
{
if ((level==3) && (rs.fields("IsLast")==0))
{ sub_Page(rs.fields("Caption"),rs.Fields("NKey"),rs.Fields("Link"));
rs.MoveNext ;
} else if ((level==3) && (rs.fields("IsLast")==1))
{
lastPage(rs.fields("Caption"),rs.Fields("NKey"),rs.Fields("Link")); rs.movenext }
}
} } }
}
Ianpbaker
Jul 17th, 2000, 05:51 AM
I Sort of understand
unfortunatly You can't embedd any asp Tags within a script tag e.g
<SCRIPT language=Javasctipt>
alert("<% = recordset("NAME")%>");
</SCRIPT>
Will completly fall arse over tit.
But you can build you script block using response.write. You have to be very careful though to get the layout right or you will get lots of script errors.
response.write "<SCRIPT language=Javasctipt>" & vbnewline
response.write "alert('" & recordset("NAME") & "'); & vbnewline
response.write "</SCRIPT>
Hope this is of help
Ian
lirlir
Jul 17th, 2000, 05:55 AM
hey Ian
i will try that 1
when i m done i ll tell u
thank
lirlir
noone
Jul 17th, 2000, 11:53 AM
Doesnt this work?:
var x= server.createobject("ADODB.Recordset");
lirlir
Jul 18th, 2000, 12:56 AM
No it doesn't work.
Ianpbaker
Jul 18th, 2000, 02:45 AM
Hi Noone
As I said earlier, you have the problem that the javascript runs on the client machine and not on the server, so getting to the database is impossible. You might be able to use the runat=Server in the script tag, it could work but then how would you get to pass it to the client side javascript to use with the tree view code. I've never tried this before and I doubt very much that it would work.
Ian
noone
Jul 18th, 2000, 01:45 PM
Ohh sorry, I didnt realise he wanted the JS to run client side. I thought it was going to run server side on an ASP page.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.