Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Scripting and ASP

    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.

  • #2
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    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.

  • #3
    New Coder
    Join Date
    Jun 2002
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Audience

    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.

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,950
    Thanks
    0
    Thanked 236 Times in 233 Posts

    Re: Audience

    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.

  • #5
    New Coder
    Join Date
    Jun 2002
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBScript will do

    Excellent.

    Thanks Glenn.

    That makes it perfectly clear. VBScript is fine for server-side stuff.

    Russ.

  • #6
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    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?

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    Code:
    <% @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.

    Last edited by whammy; 07-04-2002 at 06:43 PM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #8
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    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.

  • #9
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can't steal server-side JavaScript either - anything executed on the server isn't sent with the source code to the client.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #10
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    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?

  • #11
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts

    No special server needed...

    Code:
    <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.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #12
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    anything smaller? that i can take the time to understand?

  • #13
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <% @Language="VBScript" %>

    <script language="javascript" runat="server">
    myString = "Hello World!";
    </script>

    <% = myString %>
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #14
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    NEAT!
    I can see it, now...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •