General discussion

Locked

ASP page with javascript and stored proc

By anthonys ·
I am really new to developing Active Server pages. I have beating my head against the wall for several days now. I have attemped and failed on every try based one the following information. I need to do the following: create a form to enter a reservation for a car rental shop. The page should validate the form using javascript and write the information to my database using the command object and my prepared stored procedure. The form needs to have a drop down list, 2-8 radio buttons and severaltext boxes. It should also have several links to other ASP's and outside web sites. My stored procedure fields are as follows: Renter_Name, Renter_Phone, Rental_Data, Pick_Up_Time (morning, afternoon, evening RADIO BUTTONS), Number_Days_Rented(DROPDOWN 1-5).
I am going to interface this with either SQL Server 7 or 2000. Many thanks in advance!!!

This conversation is currently closed to new comments.

9 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

ASP page with javascript and stored proc

by SteveD In reply to ASP page with javascript ...

You don't really give us very much to go on regarding what specific problems you're running into. Since I'm sure you don't expect someone to write the whole thing for you, my best suggestion is to get hold of one of the excellent ASP books that are available. They have many working examples of this sort of page. Two that I've found helpful are "Professional Active Server Pages" published by Wrox and "Using Active Server Pages" published by Que. There are plenty of others.

I hope this helps.
Steve Diamond

Collapse -

ASP page with javascript and stored proc

by anthonys In reply to ASP page with javascript ...

My main problem is that I am not sure if the Javascript and HTML would be "nested" within the ASP page itself or have an HTML form with the Javascript in it and then link to the ASP page to validate and submit it to the inout data. Thanks for the advice about the books though!

Collapse -

ASP page with javascript and stored proc

by SteveD In reply to ASP page with javascript ...

Either way will work. It's probably simpler to keep the page separate. Your form page can be pure HTML with client-side JavaScript for validation. Your FORM tag would look something like this:

<FORM action="ProcessForm.asp" method="POST">

Of course, ProcessForm.asp has to be in the same directory as the HTML page. It will contain VBScript code (or another language if you prefer) to instantiate a connection to your database and a Command object, then populate the parameter values from the contents of the fields on the form, then execute the command. Here's a fragment of that kind of code:

ConnString = "<connection string for your database>"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open ConnString
Set cmd = Server.CreateObject("ADODB.Command")
cmd.ActiveConnection = objConn
cmd.CommandText = "<your stored procedure>"
cmd.CommandType = adCmdStoredProc
cmd.Parameters.Refresh
cmd.Parameters("@Renter_Name") = Request.Form("Renter_Name")

<other parameters here>

cmd.Execute
Set cmd = Nothing

Response.Redirect "<next page you want the user to see>"

Collapse -

ASP page with javascript and stored proc

by anthonys In reply to ASP page with javascript ...

Wasn't what I was looking for but it did help with some other issues! THANKS

Collapse -

ASP page with javascript and stored proc

by chrandrob In reply to ASP page with javascript ...

The way I generally prefer to do it is to have the javascript function on the same page as the HTML form. Instead of using a submit button or image, I use a regular button that calls a Javascript function. I usually call it validate(). Here's samplecode for the form:

<form name="sample" method="post action="formhandler.asp">
<select name="dropdown" id="dropdown">
<option value="value1">Value 1</option>
<option value="value2">Value 2</option>
<option value="value3">Value 3</option>
</select>
<br>
<input type="checkbox" name="simplecheckbox" id="simplecheckbox">Simple Checkbox
<br>
<input type="checkbox" name="fancycheckbox" id="fancycheckbox"><label for="fancycheckbox" accesskey="f" style="cursor:hand"><u>F</u>ancy Checkbox</label>
<br>
<input type="text" maxlength="50" size=30 name="textbox" id="textbox" value="Enter Name">
<br>
<input type="button" value="Send Request" onclick="validate()">
</form>

Then here is a sample javascript routine to do validation:

<SCRIPT language="javascript">
function validate() {
if (document.all.textbox.value == "") {
alert("Error: Please enter your name.");
document.all.textbox.focus();
}
else if (isNaN(document.all.textbox2.value)) {
alert("Error: You must enter a number in this field.");
document.all.textbox2.focus();
document.all.textbox2.select();
}
else {
document.forms("sample").submit();
}
}

continued in next post

Collapse -

ASP page with javascript and stored proc

by anthonys In reply to ASP page with javascript ...

It helped with some other issues!

Collapse -

ASP page with javascript and stored proc

by chrandrob In reply to ASP page with javascript ...

Post #2

You can set the form action to the same page or to another page. I use both ways equally. Send the values to your stored procedure and let it do all of the db work.

Collapse -

ASP page with javascript and stored proc

by anthonys In reply to ASP page with javascript ...

Same as above!

Collapse -

ASP page with javascript and stored proc

by anthonys In reply to ASP page with javascript ...

This question was closed by the author

Back to Web Development Forum
9 total posts (Page 1 of 1)  

Related Discussions

Related Forums