Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP object model and javascript... 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi, everyone!
Does anyone know how to write .asp pages, using javascript?
Meaning, how to access and manipulate Response, Request and other objects by means of javascript?
Any help on that, especially some example, would be greatly appreciated.
Maybe there's some tutorial on that somewhere on the WEB?

Thank you all.
 
Since Javascript is client-side, and ASP pages are created server-side, you have to be creative in how the two scripts interact. For example, to get data from a database or datafile into Javascript, the .ASP page will need to write out the information into a Javascript function. For example, here I am loading database information that has been put into a VBScript array called VBArray into two Javascript arrays named Arch and ArchV. You might notice the mixture of <% and %> which shows where the VBScript starts and stops and the Javascript begins.

//load Archived Course Array
var Arch = new Array();
var ArchV = new Array();
<% if Arch(0,0) <> &quot;&quot; then%>
var Arch = new Array(<%=ubound(VBArray,2)%>);
var ArchV = new Array(<%=ubound(VBArray,2)%>);
<%
For i = 0 to ubound(Arch,2)
%>
Arch[<%=i%>] = &quot;<%=VBArray(1,i)%>&quot;;
ArchV[<%=i%>] = &quot;<%=VBArray(0,i)%>&quot;;
<%
Next
End if
%>

Because response, request, etc. are dealt with at the server level, you can't manipulate those commands using Javascript. However, once you get the page create as you want it, you can let Javascript take over from there and redirect using Javascript based on user action on that page.

Using Javascript, we are dynamically building the URL to direct the page to pulling in values iUGID and ref_URL from the form on the page:

var URL = &quot;&quot;;
URL = &quot;javadirect.asp?ref_URL=&quot;+escape(ref_URL)+&quot;iUGID=&quot;+iUGID;
//now sending the page to the URL location
self.location = URL;

Hope that helps,
Joli
 
Actually guestg could be talking about using Javascript as the Server-side Language. I have no experience with this and no references to this, I just know it is a bad idea. Something like 99% of ASP Developers use VBScript as their Server-side Language so if you start writing Server-side in Javascript or *gasp* Perl then you are going to run into problems when it comes time for someone else to maintain the code.

Yeah, it is cool that MS felt the need to let the Developer choose the language but I think it was a poor decision. Look at all the spahgetti code that is out there in ASP already, now think if it is written in 3 or 4 different languages. It is a nightmare. This is also one of the areas of .NET that I really disagree with. Wushutwist
 
Hi Joli,
thank you for your response, but I'm a bit confused here.
First of all, I was not talking about interaction between client-side JavaScript and server-side VBScript, even though it's very interesting and I will closely look at your example. The question was about writing server-side with JavaScript. And this is where I'm confused, because from what you said, one could think, that JavaScript is only for client scripting, which really contradicts with what I've read and thought. If it's OK, I'm going to place here code for two pages and after that I'll explain what I really wanted to do.

page1.asp

<%@ Language=VBScript %>
<HTML>
<HEAD>
</HEAD>
<BODY>

<form name=&quot;list&quot; action=&quot;page2.asp&quot; method=&quot;post&quot;>
<select name=&quot;lst&quot; style=&quot;width:50px;&quot; multiple>
<option value=&quot;1&quot;>1
<option value=&quot;2&quot;>2
<option value=&quot;3&quot;>3
<option value=&quot;4&quot;>4
<option value=&quot;5&quot;>5
</select>
<input type=&quot;submit&quot;>
</form>

</BODY>
</HTML>


page2.asp


<%@ Language=VBScript %>
<HTML>
<HEAD>
</HEAD>
<BODY>

<%
dim arr,i
arr = split(Request.Form(&quot;lst&quot;),&quot;,&quot;)
for i=0 to ubound(arr)
Response.Write(arr(i)& &quot;<br>&quot;)
next
%>

</BODY>
</HTML>


Page2.asp is using VBScript. The question is whether or not I can do the same thing, using JavaScript at server as in <%@language=JavaScript%> and so on?

Thank you.
 
Sorry, I jumped to an assumption that you were talking about Javascript on the client side. We use a mixture of Javascript (for client side) and VBScript (for server side) which is where the example came from. I'm not familiar with javascript on the server side.

Joli
 
It's OK.
Thank you anyway. Just one request, though. If, by any chance, you'll come across something like this, I'd really appreciate if you'd let me know or post it . It's not like emergency or something, but you never know what can come in handy. Right?

Here's my e-mail: sgluzberg@hotmail.com

Thank you very much.
Have a great day.
 
A diehard Javascript fan? If you really want to work with server side Javascript, why not go straight to the source and work with JSP (JavaServer Pages). Here is a link that discusses the technology for beginners:


What, mutiny in the ASP forum? LOL Personally, I'm quite content with Javascript on the client side and VBScript w/ASP. Rob Marriott
rob@career-connections.net
 
Dear Rob,
there's no mutiny in the Forum.
I hate JavaScript no matter where it is, on the server or on client. I just got curious about usage of JavaScript on server and thought that maybe it'd be interesting for others is all.
I'm sorry if it's been an inconvenience for you.
 
No, I was suggesting that I was committing mutiny by recommending JSP. I myself like to work with Javascript on the client side. I just hate all of the BOM incompatibilities. Rob Marriott
rob@career-connections.net
 
I totally agree with you about all these browsers' incompatibility problems. By the way, in case anybody is interested, I've solved my problem with using ASP OM with JavaScript on server. At least at the posted level of complexity. Just used the following piece of code instead of VBScript in page2.asp


<%
var str = &quot;&quot;;
var ind;
var arr;
str = str + Request.Form(&quot;lst&quot;);
arr = str.split(&quot;,&quot;);
for (ind=0;ind<arr.length;ind++)
Response.Write(arr[ind]+ &quot;<br>&quot;);
%>


Thanks to all you, guys, for your Responses.
 
Try to use this in your asp pages
and then put your JS code in place of VBS code
<%@ Language=JScript %>
<%
var rs=new Server.CreateObject(&quot;ADODB.Recordset&quot;);
//...
%>
________

George, M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top