OK, stick with VBScript on the server. That's everything between the <% and %> tags. On the client, use JavaScript. It's widely used and there's a huge forum here on Tek Tips for it. forum216
Here's how a basic form submittal works with JavaScript as the client side script and VBScript as the server side script. I'll give you examples of two pages here.
Page 1 - test1.asp
Code:
<%@ Language=VBScript %>
<% Option Explicit %>
<% Response.Buffer = True %>
<html>
<head>
<script Language="JavaScript">
<!--
function checkForm() {
if(document.form1.first.value == "") {
window.alert("Please provide a first name.")
return false
}
if(document.form1.last.value == "") {
window.alert("Please provide a last name.")
return false
}
if(window.confirm("Are you sure you want to submit ??")) {
return true
} else {
return false
}
}
//-->
</script>
</head>
<body>
<form name="form1" action="test2.asp" onSubmit="return checkForm();">
First Name: <input type="text" name="first"><br>
Last Name: <input type="last" name="last"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Here's the 2nd page.
Page 2 - test2.asp
Code:
<%@ Language=VBScript %>
<% Option Explicit %>
<% Response.Buffer = True %>
<html>
<head>
</head>
<body>
This is the information you submitted.<br>
<b>First Name: </b><%=Request.Form("first")%><br>
<b>Last Name: </b><%=Request.Form("last")%>
</body>
</html>
Now, just load both of those pages into the same folder on the web server. Study both pages carefully. You'll notice that both pages have the same three lines at the top. You want all of your ASP pages to have these three lines at the top. You'll also notice that the commands on those three lines are surrounded by <% and %> tags. That means that the server is going to try to execute those commands. If any text is not between the <% and %> tags, then the server is going to completely ignore it and just send it down the pipe to the browser. Which is what you will want for about 80% of your contents. Now test1.asp does not have any other server side script other than the first three lines which are really instructions to the server on how to treat the page. The rest of the page is all HTML with a block of JavaScript in between the <head></head> tags. 95% of the time your JavaScript will be between those tags.
In the test1.asp page, there is a basic form. Enter your first name and last name and a submit button. If you study the opening form tag you'll see that we're submitting the information to test2.asp. But notice the
onSubmit event handler. This tells the browser to run the JavaScript function
checkForm() before submitting and don't submit the form unless that function returns a
true response. Now study that function in the block of JavaScript code. You'll see that we're making sure that both text fields have something in them and if not, you get an alert followed by a
return false which tells the form not to submit. If the first two conditions test correct, I've given an example of a
confirm message box. This will do one thing or another depending on if the user clicks OK or cancel. If the user clicks OK, then the function returns
true back to the form. If cancel is pressed, the function returns
false back to the form. At any rate, the form will only submit if the function returns
true.
Now, look at test2.asp. This page does not have any JavaScript at all. It only has two commands that are surrounded by the <% %> tags. That means that these commands are going to be processed on the server
BEFORE the server even sends the document to the page. Go ahead and submit a first and last name. When you get the second page displaying what you've submitted, View the Source. You'll notice that you won't see the Server Side code in the source. All you get is the first and last name. That's because the
<%= tag is the equivalant of
<%Response.Write method so ASP is actually writing those values to the page before they even leave the server and head for the browser.
Go ahead and play around with it and let me know if you have any other questions. Of course, I can't teach you all about ASP and JavaScript here, but I can point you to three really great books, all available at Amazon.
JavaScript Bible By: Danny Goodman
Mastering ASP By: A. Russell Jones
ASP Developer's Guide By: Greg Buczek
ToddWW