Run SQL on form button and output result on page

Discussion in 'ASP General' started by David, Apr 13, 2007.

  1. David

    David Guest

    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
    David, Apr 13, 2007
    #1
    1. Advertising

  2. David

    Mike Brind Guest

    "David" <> wrote in message
    news:...
    > 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

    --
    Mike Brind
    Mike Brind, Apr 14, 2007
    #2
    1. Advertising

  3. David

    Guest

    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)">
    , Apr 20, 2007
    #3
  4. wrote:
    > 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.
    Bob Barrows [MVP], Apr 20, 2007
    #4
  5. David

    Guest

    On Apr 20, 3:48 pm, "Bob Barrows [MVP]" <>
    wrote:
    > wrote:
    > > 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
    , May 4, 2007
    #5
  6. David

    Guest

    On Apr 20, 3:48 pm, "Bob Barrows [MVP]" <>
    wrote:
    > wrote:
    > > 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.
    , May 4, 2007
    #6
  7. wrote:
    > On Apr 20, 3:48 pm, "Bob Barrows [MVP]" <>
    > wrote:
    >> wrote:
    >>> 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">

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

    <snip>
    > 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,
    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
    Bob Barrows [MVP], May 4, 2007
    #7
  8. wrote:
    >
    > 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.

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
    Bob Barrows [MVP], May 4, 2007
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. J.Ram
    Replies:
    7
    Views:
    639
  2. Pavel
    Replies:
    7
    Views:
    510
    Pavel
    Sep 19, 2010
  3. Michael Tan
    Replies:
    32
    Views:
    929
    Ara.T.Howard
    Jul 21, 2005
  4. J Kester
    Replies:
    0
    Views:
    278
    J Kester
    Dec 23, 2003
  5. Daniel H.

    form button onclick and hide result

    Daniel H., Apr 30, 2004, in forum: Javascript
    Replies:
    5
    Views:
    133
    Thomas 'PointedEars' Lahn
    May 20, 2004
Loading...

Share This Page