Run SQL on form button and output result on page

D

David

Hi,

I have an asp page with a form.
A user enters a serial number in a text box.

I want to add a button next to the text box such as 'Check Serial' to
run some SQL in the background to see if that serial exists in the
table, and then output 'Serial found' or 'Serial Not Found' next to
the text box, so the user can decide whether to continue with the
form.


Appreciate your help.



Thanks


David
 
M

Mike Brind

David said:
Hi,

I have an asp page with a form.
A user enters a serial number in a text box.

I want to add a button next to the text box such as 'Check Serial' to
run some SQL in the background to see if that serial exists in the
table, and then output 'Serial found' or 'Serial Not Found' next to
the text box, so the user can decide whether to continue with the
form.

Have a look at the xmlhttpobject in javascript: www.w3schools.com/ajax
 
X

xxshoexx

Using VB and ADO I have stored proc that checks for a value and give
the return value. And kicks off the event onBlur

<SCRIPT LANGUAGE="vbscript">
Public Sub getID(id)
Dim cn: Set cn = CreateObject("ADODB.Connection")
Dim cmd: Set cmd = CreateObject("ADODB.Command")
Dim rs: Set rs = CreateObject("ADODB.Recordset")

'cn.Open "db.udl"
cn.Open "Provider=SQLOLEDB.1;Password=[Password];Persist
Security Info=True;User ID=[UserID];Initial Catalog=[Database];Data
Source=[Server Name]"
cn.CursorLocation = 3
cmd.ActiveConnection = cn
cmd.CommandType = 4

cmd.CommandText = "[dbo].[View:GetID]"
cmd.Parameters.Append (cmd.CreateParameter ("@ID",3, 1, 0,
Null ))
cmd.Parameters.Item("@ID").Value = id
rs.Open cmd

If rs.RecordCount = 0 Then
MsgBox id & " is not a valid ID.", vbOkOnly, "Error"
document.all("WorkoutID").Value = ""
document.all("WorkoutName").innerHTML = ""
Else
document.all("WorkoutID").Value = id
document.all("WorkoutName").innerHTML =
rs.Fields.Item("Topic")

End if
End Sub
</SCRIPT>


<input name="WorkoutID" size="5" type="text"
onblur="vbscript:getId(WorkoutID.value)">
 
B

Bob Barrows [MVP]

Using VB and ADO I have stored proc that checks for a value and give
the return value. And kicks off the event onBlur

<SCRIPT LANGUAGE="vbscript">
Public Sub getID(id)
Dim cn: Set cn = CreateObject("ADODB.Connection")
Dim cmd: Set cmd = CreateObject("ADODB.Command")
Dim rs: Set rs = CreateObject("ADODB.Recordset")

'cn.Open "db.udl"
cn.Open "Provider=SQLOLEDB.1;Password=[Password];Persist
Security Info=True;User ID=[UserID];Initial Catalog=[Database];Data
Source=[Server Name]"

Dangerous! You do realize this is all visible to the user simply via
View|Source ??
 
X

xxshoexx

Using VB and ADO I have stored proc that checks for a value and give
the return value. And kicks off the event onBlur
<SCRIPT LANGUAGE="vbscript">
Public Sub getID(id)
Dim cn: Set cn = CreateObject("ADODB.Connection")
Dim cmd: Set cmd = CreateObject("ADODB.Command")
Dim rs: Set rs = CreateObject("ADODB.Recordset")
'cn.Open "db.udl"
cn.Open "Provider=SQLOLEDB.1;Password=[Password];Persist
Security Info=True;User ID=[UserID];Initial Catalog=[Database];Data
Source=[Server Name]"

Dangerous! You do realize this is all visible to the user simply via
View|Source ??

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

not if you put it inside of server side tags
 
X

xxshoexx

Using VB and ADO I have stored proc that checks for a value and give
the return value. And kicks off the event onBlur
<SCRIPT LANGUAGE="vbscript">
Public Sub getID(id)
Dim cn: Set cn = CreateObject("ADODB.Connection")
Dim cmd: Set cmd = CreateObject("ADODB.Command")
Dim rs: Set rs = CreateObject("ADODB.Recordset")
'cn.Open "db.udl"
cn.Open "Provider=SQLOLEDB.1;Password=[Password];Persist
Security Info=True;User ID=[UserID];Initial Catalog=[Database];Data
Source=[Server Name]"

Dangerous! You do realize this is all visible to the user simply via
View|Source ??

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup


Also can just do async calls with it.
 
B

Bob Barrows [MVP]

not if you put it inside of server side tags

But your example shows it in a client-side script element.
At least now you are aware of the desirability to do this in server-side
code,
 
B

Bob Barrows [MVP]

Also can just do async calls with it.

And why is this relevant? If it is in client-side script, the user can see
it, whether async calls are done with it or not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top