Search Tools Links Login

Beginners guide [2] to ASP filled with examples!


Here is my second tutorial in basic ASP scripting. Leave comments if you want. Or have questions.

Original Author: snowboardr

Code





Jason's Tutorial..





  


ASP
   - Active Server Pages [Tutorial 2] - Tutorial
   1



  


  


  


  

Getting
   Scriptname

  

<%


  

'This
    is very useful, using this in your code will allow you to change the name
    of your page as much as you want without having to chang any source


  

ScriptName
    = Request.ServerVariables("SCRIPT_NAME")


  

Response.write(ScriptName)


  

%>


  
default.asp
Live Example at http://www.irideforlife.com/go/default2.asp

 




  


  

Redirect
   to url..

  

<%


  

Response.Redirect
    "http://www.planetsourcecode.com"


  

%>


  

 




  


  


  


  

Stop
   writing the page..

  

<%


  



    
Response.write
    "Hello there, this page needs to..."


  

Response.End

    
Response.write
    "Have an ending?"


  

%>


  
Hello
   there, this page needs to...
Live Example at http://www.irideforlife.com/go/default2.asp

 




  


  


  


  

Count
   the number of chr's in your string

  

<%


  

MyString
    = "1234567"


  



    
Response.write
    len(MyString)


  

%>


  
7
Live Example at http://www.irideforlife.com/go/default2.asp

 




  


  


  

Select
   Case

  

<%


  

MyCase =
    "3"


  

Select Case
    MyCase


  

Case
    1


  

Response.write
    "its 1"


  

Case
    2


  

Response.write
    "its 2"


  

Case
    3


  

Response.write
    "its 3"


  

End
    Select


  

%>


  

  

Live Example at http://www.irideforlife.com/go/default2.asp


  

 




  


  


  

Select
   Case QueryString

  

<%


  

'<%=
    ScriptName & "?case=one" %>

    '<%= ScriptName & "?case=two" %>

    '<%= ScriptName & "?case=three"%>


    


  

TheCase =
    Request.QueryString("case")


  

Select Case
    TheCase


  

Case
    "one"


  

Response.write
    "its 1"


  

Case
    "two"


  

Response.write
    "its 2"


  

Case
    "three"


  

Response.write
    "its 3"


  

End
    Select


  

%>


  
Live Example at http://www.irideforlife.com/go/default2.asp

 




  


  


  

Writing
   m / dd/yyyy

  

<%


  

TheMonth
    = month(date)


  

TheDay
    = day(date)


  

TheYear
    = year(date)


  

Response.write(TheMonth)
    & "/" & TheDay & "/" & TheYear


  

'
    & Seperates each thing.


  

%>


  
Live Example at http://www.irideforlife.com/go/default2.asp

 




  


  


  

Writing
   HH:MM:SS

  

<%


  

TheHour
    = hour(time)


  

TheMinute
    = minute(time)


  

TheSecond
    = second(time)


  

Response.write(TheHour)
    & ":" & TheMinute & ":" & TheSecond


  

'
    & Seperates each thing.


  

%>


  
Live Example at http://www.irideforlife.com/go/default2.asp

 


 




  


  


  

Getting
   Form Results

  

<%


  

Dim age


  

age = Request.Form("age")


  

%>


  

<form
    name="form1" method="post" action="<%=ScriptName
    & "?submit=form" %>">

    <table width="9%" border="0" cellspacing="0"
    cellpadding="0">

    <tr>

    <td><font size="2" face="Verdana, Arial, Helvetica,
    sans-serif">&lt;18</font></td>

    <td><font size="2" face="Verdana, Arial, Helvetica,
    sans-serif">

    <input type="radio" name="age" value="<18"
    <% if age = "<18" then Response.write
    "checked" %>
>

    </font></td>

    </tr>

    <tr>

    <td><font size="2" face="Verdana, Arial, Helvetica,
    sans-serif">18-21</font></td>

    <td><font size="2" face="Verdana, Arial, Helvetica,
    sans-serif">

    <input type="radio" name="age" value="18-21"
    <% if age = "18-21" then Response.write
    "checked" %>
>

    </font></td>

    </tr>

    <tr>

    <td><font face="Verdana, Arial, Helvetica, sans-serif"
    size="2">22 &gt;</font></td>

    <td><font size="2" face="Verdana, Arial, Helvetica,
    sans-serif">

    <input type="radio" name="age" value="22>"
    <% if age = "22>" then Response.write
    "checked" %>
>

    </font></td>

    </tr>

    <tr>

    <td colspan="2">

    <input type="submit" name="Submit" value="Submit">

    <%


  

If
    Request.QueryString("submit") = "form"


  

If
    NOT age = "" Then ' Lets make sure the
    form wasn't submited with nothing checked.


  


    Response.write "You are in the "
    & age & " age range!


  

End
    If


  

End
    if


  

%>


  

</td>

    </tr>

    </table>

    </form>


  
Live Example at http://www.irideforlife.com/go/default2.asp

 


 


 




  


  


  


  

Please
    post comments below and vote if this helped...thanks!


  

-Jason


  

  

 


  

 


 




About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 97 times

Categories

ASP/ HTML

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.