Solved

How to handle a click event in asp

Posted on 2004-09-13
7
276 Views
Last Modified: 2010-04-17
Hi,
I have a text box on a page and a command button. When user enter data into the textbox and then click on the button, a search will be done in the database and data will be returned and displayed on the page. I am able to return the data but how do I set up the click event to tahe the data from the textbox and insert it into my sql string. This is the code I have so far

<%@ LANGUAGE="VBSCRIPT" %>
<%  
Option Explicit
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Search_Result</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">




</head>

<body>
<p>&nbsp;</p>

<table width="210" border="0" align="center" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
  <tr>
    <td>Search by Invoice Number </td>
  </tr>
  <tr>
    <td><form action="result" method="get/post" name="invoice" id="invoice">
      <input name="invoice" type="text" class="title" id="invoice" value="123456" size="10" maxlength="10">
      <input name="Button" type="button" class="button" align="right" onmouseover="this.className='buttonon'" onmouseout="this.className='button'" value="Search">
    </form></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>

</body>

</html>


<%

' -- Declare Variables
Dim objConn                  ' Our Connection Object
Dim objRS                  ' Our Recordset Object
Dim strSQL                  ' Our SQL String to access the database
Dim strConnection            ' Our Connection string to access the database
Dim i      
                  ' a counter variable

' -- Create objects
Set objConn = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")




objConn.Open "Provider=sqloledb;" & _
           "Data Source=localhost;" & _
           "Initial Catalog=test;" & _
           "Integrated Security=SSPI"







' -- Our SQL Statement

strSQL = "select * from tinvoice where inv_no =12345"

' -- Populate our Recordset with data
set objRS = objConn.Execute (strSQL)


if (objRS.BOF and objRS.EOF) then
      response.write "No records found"
      response.end
End if

%>

<TABLE BORDER="1" CELLPADDING="2" CELLSPACING="1" WIDTH="100%">



<%
      ' -- Output the Field Names as the first row in the table
      Response.Write "<TR BGCOLOR=""#CCffCC"">"
      For i = 0 to objRS.Fields.Count -1
            Response.Write "<TH>" & objRS.Fields(i).Name  & "</TH>"
      Next
      Response.write "</TR>"

' -- Now output the contents of the Recordset
      objRS.MoveFirst
      Do While Not objRS.EOF
            ' -- output the contents
            Response.Write "<TR>"
            For i = 0 to objRS.Fields.Count - 1
                  Response.Write "<TD>" & objRS.Fields(i) & "</TD>"
            Next
            Response.write "</TR>"
            ' -- move to the next record
            objRS.MoveNext
      Loop

objRS.Close
      set objRS = Nothing
      objConn.Close
      set objConn = Nothing





%>
0
Comment
Question by:delcom5
  • 2
7 Comments
 
LVL 35

Accepted Solution

by:
YZlat earned 25 total points
Comment Utility
you should use form submit. Put <form> tag on the form and replace your Button with Submit button. Set the form's action to your page name.asp. For example if you mage is result.asp, have <form name="form1" method="post" action="result.asp">:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Search_Result</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">




</head>

<body>
<p>&nbsp;</p>

<table width="210" border="0" align="center" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
  <tr>
    <td>Search by Invoice Number </td>
  </tr>
  <tr>
    <td><form action="result.asp" method="post" name="invoice" id="invoice">
      <input name="invoice" type="text" class="title" id="invoice" value="123456" size="10" maxlength="10">
      <input name="Button1" type="submit" class="button" align="right" onmouseover="this.className='buttonon'" onmouseout="this.className='button'" value="Search">
    </form></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>

</body>

</html>

0
 

Assisted Solution

by:sajithnair
sajithnair earned 25 total points
Comment Utility
In the form tab give the name or the script .. right now you have given result.. I assume your page name is result.asp so change the form tag as follows.

<form action="result.asp" method="post" name="invoice" id="invoice">

Now in the SQL query replace 12345 with the value from textbox as follows

' -- Our SQL Statement

strSQL = "select * from tinvoice where inv_no =" & Request.form("invoice")

Now change the type of the button from "button" to "submit" as follows

<input name="Button" type="submit" class="button" align="right" onmouseover="this.className='buttonon'" onmouseout="this.className='button'" value="Search">


Hope this should help you :)
Cheers
Sajith
0
 

Expert Comment

by:sajithnair
Comment Utility
I have an objection. The chosen comment doesn't fullfill the answer. It has not described how to take the data in the query after the form is submitted.

Thanks
Sajith
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Report events not being triggered 8 97
copyEvens challenge 6 63
sumDigits  challenge 7 59
Path of Workbook 3 42
RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now