Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Query Db using ASP and Javascript


Message #1 by stephen_marrs@h... on Thu, 22 Aug 2002 08:45:06
Hello,Could anyone with knowledge of ASP help.I need to create a form 
that uses ASP to allow users to choose between different criteria which 
will query a db and return a list of suitable dog breeds to them using 
ASP and JavaScript. The criteria are Size,Grooming,Exercise and Space and 
each of these has the following attributes to choose from,e.g.Considerable
(Con),Moderate(Mod) or Little(Lt)and in the case of size S,M,L and XL.
This is what I have come up with so far

<%@ LANGUAGE = JavaScript%>
<HTML>
<BODY>
 <h3>Dog Breed Selector</h3>
 <p>Please choose what Size of dog you would prefer:</p>
 <form>
 <table>
 <td><input type='radio' name='size' value='S'>Small</td>
 <td><input type='radio' name='size' value='M'>Medium</td>
 <td><input type='radio' name='size' value='L'>Large</td>
 <td><input type='submit' value='Find a Dog'></td>

<%
// Open connection to database, then populate a recordset with list of 
stock
   var adoConnection = Server.CreateObject("ADODB.Connection");
   var adoRecordSet;
   var mySQL;
   adoConnection.Open("DSN=DogDSN");
   var mySQL = "SELECT BreedName" + 
      " FROM Breeds WHERE Size='" & Request.Form('size')&"'";
   adoRecordSet = adoConnection.Execute(mySQL);

// Loop through recordset and write Breed Names out to page
   while ( adoRecordSet.Eof == false )
   {
%>
<TR>
   <TD><%=adoRecordSet("BreedName").Value%></TD>
   
  
  
</TR>
<%
   adoRecordSet.MoveNext();
   }

// Close Recordset and connections 
// and release memory used by Recordset and Connection objects
   adoRecordSet.Close();
   adoRecordSet = null;
   adoConnection.Close();
   adoConnection = null;
%>
<%Response.Write(Request.Form("size"))
%>

</BODY>

What would I need to change and add to this to meet my requirements?



Message #2 by stephen_marrs@h... on Thu, 22 Aug 2002 12:54:31
> Hello,Could anyone with knowledge of ASP help.I need to create a form 
t> hat uses ASP to allow users to choose between different criteria which 
w> ill query a db and return a list of suitable dog breeds to them using 
A> SP and JavaScript. The criteria are Size,Grooming,Exercise and Space 
and 
e> ach of these has the following attributes to choose 
from,e.g.Considerable
(> Con),Moderate(Mod) or Little(Lt)and in the case of size S,M,L and XL.
T> his is what I have come up with so far

> <%@ LANGUAGE = JavaScript%>
<> HTML>
<> BODY>
 > <h3>Dog Breed Selector</h3>
 > <p>Please choose what Size of dog you would prefer:</p>
 > <form>
 > <table>
 > <td><input type='radio' name='size' value='S'>Small</td>
 > <td><input type='radio' name='size' value='M'>Medium</td>
 > <td><input type='radio' name='size' value='L'>Large</td>
 > <td><input type='submit' value='Find a Dog'></td>

> <%
/> / Open connection to database, then populate a recordset with list of 
s> tock
 >   var adoConnection = Server.CreateObject("ADODB.Connection");
 >   var adoRecordSet;
 >   var mySQL;
 >   adoConnection.Open("DSN=DogDSN");
 >   var mySQL = "SELECT BreedName" + 
 >      " FROM Breeds WHERE Size='" & Request.Form('size')&"'";
 >   adoRecordSet = adoConnection.Execute(mySQL);

> // Loop through recordset and write Breed Names out to page
 >   while ( adoRecordSet.Eof == false )
 >   {
%> >
<> TR>
 >   <TD><%=adoRecordSet("BreedName").Value%></TD>
 >   
 >  
 >  
<> /TR>
<> %
 >   adoRecordSet.MoveNext();
 >   }

> // Close Recordset and connections 
/> / and release memory used by Recordset and Connection objects
 >   adoRecordSet.Close();
 >   adoRecordSet = null;
 >   adoConnection.Close();
 >   adoConnection = null;
%> >
<> %Response.Write(Request.Form("size"))
%> >

> </BODY>

> What would I need to change and add to this to meet my requirements?

> 

Could anybody please help me with this as I need it urgently for Monday

  Return to Index