rah111
07-04-2002, 05:25 AM
Hi all.
This is just a question of style and/or philosophy.
I understand that the default language for ASP is VBScript.
I also understand that JavaScript is a better choice in terms of reaching the largest possible audience when using scripting along with HTML.
But is it correct to say that if I only use VBScript within ASP that I am not jeopardising the potential audience as I would be if I used VBScript instead of JavaScript in straightforward HTML?
If so, are there any advantages at all to using JavaScript within ASP instead of VBScript?
Thanks in advance.
Russell.
Morgoth
07-04-2002, 05:34 AM
First off, use both if you want to... Java script can do a few things, while ASP can do others.
I don't see what you mean by an audience. If people go to a site, it's for information, not the code the person uses. But if you mean something like the number of people on this forum that use the certain langauge, then you must realize there are many forums out their for differnt languages.
I think all the old web langauges are used equal all around.
rah111
07-04-2002, 05:44 AM
Thanks Morgoth.
By audience I simply mean people with the right browser.
If I use JavaScript instead of VBScript in normal HTML then more people (ie. a bigger audience) in the world can see my web page the way I intended it to be seen. Is that not true?
The main point of my question was whether or not that same restriction (ie. using VBScript diminishes the audience) applied within ASP, or whether using JavaSCript or VBScript within ASP had no effect at all based on what browser someone was using.
Cheers.
Russell.
glenngv
07-04-2002, 05:51 AM
let's make it clearer.
It's better to use client-side Javascript than using client-side VBScript because client-side Javascript is supported on all kinds of browsers.
In server-side, it doesn't matter if you are using server-side VBScript or server-side Javascript since it will be interpreted by the Web server not the client machine.
Originally posted by rah111
Thanks Morgoth.
By audience I simply mean people with the right browser.
If I use JavaScript instead of VBScript in normal HTML then more people (ie. a bigger audience) in the world can see my web page the way I intended it to be seen. Is that not true?
The main point of my question was whether or not that same restriction (ie. using VBScript diminishes the audience) applied within ASP, or whether using JavaSCript or VBScript within ASP had no effect at all based on what browser someone was using.
Cheers.
Russell.
rah111
07-04-2002, 05:53 AM
Excellent.
Thanks Glenn.
That makes it perfectly clear. VBScript is fine for server-side stuff.
Russ.
Morgoth
07-04-2002, 04:54 PM
I have never heard of js used as a server side language...
But I know if the borswer you use can see html then any server side langauge is ok. All the scripts are executed on the server and not the borswer. All you get out of server side languages are either text or html. Am I mistaken?
whammy
07-04-2002, 06:40 PM
Let me put it this way - as Glenn says, what language is executed on the server doesn't matter (and you CAN use JavaScript in conjunction with ASP - and even ASP/VBScript, I use both in some of my applications).
ASP runs the scripts on the server-side, and returns pure HTML to the client - however this can also contain Client-Side javascript, just like any other HTML.
Here's an example:
<% @Language="VBScript" %>
<% Option Explicit %>
<%
Dim CurrentMonth, CurrentDay, CurrentYear, i
CurrentMonth = Month(Date)
CurrentDay = Day(Date)
CurrentYear = Year(Date)
'''''''''''''Main Program
WriteHeader()
WriteForm()
WriteFooter()
'''''''''''''End Main Program
Sub WriteHeader() %>
<html>
<head>
<script language="JavaScript" type="text/javascript">
<!--
function showdate(){
var f = document.myform;
alert(f.month.options[f.month.selectedIndex].value + '/' + f.day.options[f.day.selectedIndex].value + '/' + f.year.options[f.year.selectedIndex].value);
}
// -->
</script>
</head>
<body>
<form name="myform">
<table>
<tr>
<td><b>Choose a date below:</b></td>
</tr>
<tr>
<td>
<% End Sub %>
<% Sub WriteForm()
With Response
.Write(" <select name=""month"">" & vbcrlf)
For i = 1 to 12
If CurrentMonth = i Then
.Write(" <option value=""" & i & """ selected=""selected"">" & i & "</option>" & vbcrlf)
Else
.Write(" <option value=""" & i & """>" & i & "</option>" & vbcrlf)
End If
Next
.Write(" </select>" & vbcrlf)
.Write(" <select name=""day"">" & vbcrlf)
For i = 1 to 31
If CurrentDay = i Then
.Write(" <option value=""" & i & """ selected=""selected"">" & i & "</option>" & vbcrlf)
Else
.Write(" <option value=""" & i & """>" & i & "</option>" & vbcrlf)
End If
Next
.Write(" </select>" & vbcrlf)
.Write(" <select name=""year"">" & vbcrlf)
For i = CurrentYear-5 to CurrentYear+5
If CurrentYear = i Then
.Write(" <option value=""" & i & """ selected=""selected"">" & i & "</option>" & vbcrlf)
Else
.Write(" <option value=""" & i & """>" & i & "</option>" & vbcrlf)
End If
Next
.Write(" </select>" & vbcrlf)
.Write(" <input type=""button"" value=""Show Date"" onclick=""showdate()"" />")
End With
End Sub %>
<% Sub WriteFooter() %>
</td>
</tr>
</table>
</form>
</body>
</html>
<% End Sub %>
Demo here (http://www.solidscripts.com/choosedate.asp).
:)
Morgoth
07-04-2002, 08:56 PM
The only reason I feel I don't like using js or a language like it, might be because it can be stolen. ASP can be hacked and stolen if the server is not protected, but the person trying to steal something like that comes along 0.01% of the time.
whammy
07-04-2002, 09:24 PM
You can't steal server-side JavaScript either - anything executed on the server isn't sent with the source code to the client.
Morgoth
07-04-2002, 10:05 PM
I see...
Is there a samll example of it I can try for myself? Do I need a certain type of server to run it?
whammy
07-05-2002, 05:26 PM
<script language="javascript" runat="server">
function ValidEmail(EmailAddr){
if(EmailAddr){
var vemail = /^[a-z0-9]+([-_\.]?[a-z0-9])+@[a-z0-9]+([-_\.]?[a-z0-9])+\.[a-z]{2,4}$/i
var EmailTest = (vemail.test(EmailAddr));
return EmailTest;
}
}
</script>
<%
Dim Email, EmailGood
Email = Request.Form("Email")
EmailGood = ValidEmail(Email)
%>
<html>
<head>
<title>Email Test</title>
</head>
<body>
<p><% If Email <> "" Then Response.Write("Is " & chr(34) & Email & chr(34) & " a valid email address? ") %>
<b><% = EmailGood %></b></p>
<form name="myform" action="emailtest.asp" method="post">
<input type="text" name="Email"></input><input type="submit" value="Submit"></input>
</form>
</body>
</html>
Demo here (http://www.solidscripts.com/emailtest.asp). :)
Morgoth
07-06-2002, 12:31 AM
anything smaller? that i can take the time to understand?
whammy
07-07-2002, 01:33 AM
<% @Language="VBScript" %>
<script language="javascript" runat="server">
myString = "Hello World!";
</script>
<% = myString %>
Morgoth
07-07-2002, 02:02 AM
NEAT!
I can see it, now...