Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Desperate... Need to validate form field against database

    Please Help..............

    I need to validate a form field against a list of numbers in a database, This should be simple but I can't figure it out..

    Here is the code for the recordset, the items are in the ITLITM column(16,000 lines)
    I need to run a check on each field(32 times) when they advance to the next field.(onBlur or onChange)

    Code:
    <%
    Dim RS_NumCheck1
    Dim RS_NumCheck1_numRows
    
    Set RS_NumCheck1 = Server.CreateObject("ADODB.Recordset")
    RS_NumCheck1.ActiveConnection = MM_JDE_DEV_STRING
    RS_NumCheck1.Source = "SELECT IMLITM  FROM TESTDTA.F4101"
    RS_NumCheck1.CursorType = 0
    RS_NumCheck1.CursorLocation = 2
    RS_NumCheck1.LockType = 1
    RS_NumCheck1.Open()
    
    RS_NumCheck1_numRows = 0
    %>
    Thanks in advance

  • #2
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    I actually sat down and started to try and write a response to your post, but stopped when I realised there are too many ways to do what you want.

    The code you have posted up is simply a database query that selects all the IMLITM (or ITLITM as you call it elsewhere in your post). However this should be more like what you are trying to do:
    Code:
    Dim RS_NumCheck1
    Dim imlitmToCheck
    imlitmToCheck = 13
    
    Set RS_NumCheck1 = Server.CreateObject("ADODB.Recordset")
    RS_NumCheck1.ActiveConnection = MM_JDE_DEV_STRING
    RS_NumCheck1.Source = "SELECT imlitm  FROM TESTDTA.F4101 WHERE imlitm=" & imlitmToCheck
    RS_NumCheck1.CursorType = 0
    RS_NumCheck1.CursorLocation = 2
    RS_NumCheck1.LockType = 1
    RS_NumCheck1.Open()
    
    If RS_NumCheck1.EOF Then
      'imlitmToCheck does not exist in TESTDTA.F4101
    Else
      'imlitmToCheck is already in TESTDTA.F4101
    End If
    
    RS_NumCheck1.Close()
    Set RS_NumCheck1 = Nothing
    One suggestion (and i can think of at least 3 others) might be to have this:

    form page:
    Code:
    <script>
    function openImlitmCheckWindow(imlitmToCheck) {
      if( imlitmToCheck.length < 1 ) 
        return;
      else
        window.open("popup.asp?imlitmToCheck="+imlitmToCheck);
    }
    </script>
    <form name="frm" action="form_handler.asp" method="post">
    <input type="text" name="txtImlitmtoCheck">
    <input type="button" value="check imlitm" onclick="openImlitmCheckWindow(document.frm.txtImlitmtoCheck.value);">
    </form>
    popup page:
    Code:
    If Len(Request.QueryString("imlitmToCheck")) > 0 Then
      Dim RS_NumCheck1
    
      Set RS_NumCheck1 = Server.CreateObject("ADODB.Recordset")
      RS_NumCheck1.ActiveConnection = MM_JDE_DEV_STRING
      RS_NumCheck1.Source = "SELECT imlitm  FROM TESTDTA.F4101 WHERE imlitm=" & Request.QueryString("imlitmToCheck")
      RS_NumCheck1.CursorType = 0
      RS_NumCheck1.CursorLocation = 2
      RS_NumCheck1.LockType = 1
      RS_NumCheck1.Open()
    
      If RS_NumCheck1.EOF Then
        Response.Write "imlitm not in database, ok to continue<br><a href=""javascript: window.close();"">Close window</a>"
      Else
        Response.Write "<scr"&"ipt>opener.document.frm.txtImlitmtoCheck.value = '';</scr"&"ipt>"
        Response.Write "imlitm already exists in database, the form field has been cleared so you can enter in a new imlitm<br><a href=""javascript: window.close();"">Close window</a>"
      End If
    
      RS_NumCheck1.Close()
      Set RS_NumCheck1 = Nothing
    Else
      Response.Write "No imlitm has been passed to this page to be checked"
    End If
    This would mean there was a button next to the imlitm input field on the form that would pop up a window that would check the database for the value in the imlitm form field. it would then either clear the text box if imlitm is found in the database or allow the user to continue if imlitm is not found in the database. It also displays the accompanying message of success or failure of the check and a link to close the window.

    This is a very rough and ready script designed to show you how something might be done. Please don't forget that you always need to validate the form server side, don't rely solely on javascript for form validations as it can be easily bypassed.

    I hope this helps someway in answering your question. There are many ways to do what you broadly ask for, please in your next postings be more specific and try and provide a much fuller amount of relevant code for us to look at ;-)

    Cheers

    m_n
    Last edited by martin_narg; 06-05-2005 at 05:38 AM.
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #3
    New to the CF scene
    Join Date
    Jun 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    what I was actually trying to do was verify that the number entered in the form field was in the database before continuing. I am using this form to input item numbers on page 1 and then on page 2 print the barcodes of the entered item numbers. I need to validate those items entered on page 1 before continuing to page 2.

    Sorry for the lack of detail on first post

    Here is complete code from page 1

    Code:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <!--#include file="../Connections/JDE_DEV.asp" -->
    <%
    Dim RS_NumCheck1
    Dim RS_NumCheck1_numRows
    
    Set RS_NumCheck1 = Server.CreateObject("ADODB.Recordset")
    RS_NumCheck1.ActiveConnection = MM_JDE_DEV_STRING
    RS_NumCheck1.Source = "SELECT IMLITM  FROM TESTDTA.F4101"
    RS_NumCheck1.CursorType = 0
    RS_NumCheck1.CursorLocation = 2
    RS_NumCheck1.LockType = 1
    RS_NumCheck1.Open()
    
    
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    <form method="POST" name="form1">
      <table width="672" height="960" border="1" cellpadding="0" cellspacing="0" bordercolor="000000">
        <tr>
          <td  width="168px" height="112px"><table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
              <tr>
                <td height="38" colspan="2"><div align="center">
                  <input name="item1" type="text" id="item1" size="8" maxlength="8" >
                </div></td>
              </tr>
              <tr>
                <td width="42%" height="30">&nbsp;</td>
                <td width="58%" height="30">&nbsp;</td>
              </tr>
              <tr>
                <td  height="25%" colspan="2">&nbsp;</td>
              </tr>
          </table></td>
          <td  width="168px" height="112px"><table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
              <tr>
                <td height="38" colspan="2"><div align="center">
                  <input name="item2" type="text" id="item2" size="8" maxlength="8">
    </div></td>
              </tr>
              <tr>
                <td width="42%" height="30">&nbsp;</td>
                <td width="58%" height="30">&nbsp;</td>
              </tr>
              <tr>
                <td  height="25%" colspan="2">&nbsp;</td>
              </tr>
          </table></td>
          <td  width="168px" height="112px"><table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
              <tr>
                <td height="38" colspan="2"><div align="center">
                  <input name="item3" type="text" id="item3" size="8" maxlength="8">
                </div></td>
              </tr>
              <tr>
                <td width="42%" height="30">&nbsp;</td>
                <td width="58%" height="30">&nbsp;</td>
              </tr>
              <tr>
                <td  height="25%" colspan="2">&nbsp;</td>
              </tr>
          </table></td>
          <td  width="168px" height="112px"><table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
              <tr>
                <td height="38" colspan="2"><div align="center">
                  <input name="item4" type="text" id="item15" size="8" maxlength="8">
                </div></td>
              </tr>
              <tr>
                <td width="42%" height="30">&nbsp;</td>
                <td width="58%" height="30">&nbsp;</td>
              </tr>
              <tr>
                <td  height="25%" colspan="2">&nbsp;</td>
              </tr>
          </table></td>
        </tr>
        <tr>
          <td  width="168px" height="112px"><table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
              <tr>
                <td height="38" colspan="2"><div align="center">
                  <input name="item5" type="text" id="item16" size="8" maxlength="8">
                </div></td>
              </tr>
              <tr>
                <td width="42%" height="30">&nbsp;</td>
                <td width="58%" height="30">&nbsp;</td>
              </tr>
              <tr>
                <td  height="25%" colspan="2">&nbsp;</td>
              </tr>
          </table></td>
          <td  width="168px" height="112px"><table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
              <tr>
                <td height="38" colspan="2"><div align="center">
                  <input name="item6" type="text" id="item6" size="8" maxlength="8">
                </div></td>
              </tr>
              <tr>
                <td width="42%" height="30">&nbsp;</td>
                <td width="58%" height="30">&nbsp;</td>
              </tr>
              <tr>
                <td  height="25%" colspan="2">&nbsp;</td>
              </tr>
          </table></td>
          <td  width="168px" height="112px"><table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
              <tr>
                <td height="38" colspan="2"><div align="center">
                  <input name="item7" type="text" id="item18" size="8" maxlength="8">
                </div></td>
              </tr>
              <tr>
                <td width="42%" height="30">&nbsp;</td>
                <td width="58%" height="30">&nbsp;</td>
              </tr>
              <tr>
                <td  height="25%" colspan="2">&nbsp;</td>
              </tr>
          </table></td>
          <td  width="168px" height="112px"><table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
              <tr>
                <td height="38" colspan="2"><div align="center">
                  <input name="item8" type="text" id="item18" size="8" maxlength="8">
                </div></td>
              </tr>
              <tr>
                <td width="42%" height="30">&nbsp;</td>
                <td width="58%" height="30">&nbsp;</td>
              </tr>
              <tr>
                <td  height="25%" colspan="2">&nbsp;</td>
              </tr>
          </table></td>
        </tr>
        <tr>
          <td  width="168px" height="112px"><table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
              <tr>
                <td height="38" colspan="2"><div align="center">
                  <input name="item9" type="text" id="item18" size="8" maxlength="8">
                </div></td>
              </tr>
              <tr>
                <td width="42%" height="30">&nbsp;</td>
                <td width="58%" height="30">&nbsp;</td>
              </tr>
              <tr>
                <td  height="25%" colspan="2">&nbsp;</td>
              </tr>
          </table></td>
          <td  width="168px" height="112px"><table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
              <tr>
                <td height="38" colspan="2"><div align="center">
                  <input name="item10" type="text" id="item18" size="8" maxlength="8">
                </div></td>
              </tr>
              <tr>
                <td width="42%" height="30">&nbsp;</td>
                <td width="58%" height="30">&nbsp;</td>
              </tr>
              <tr>
                <td  height="25%" colspan="2">&nbsp;</td>
              </tr>
          </table></td>
          <td  width="168px" height="112px"><table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
              <tr>
                <td height="38" colspan="2"><div align="center">
                  <input name="item11" type="text" id="item18" size="8" maxlength="8">
                </div></td>
              </tr>
              <tr>
                <td width="42%" height="30">&nbsp;</td>
                <td width="58%" height="30">&nbsp;</td>
              </tr>
              <tr>
                <td  height="25%" colspan="2">&nbsp;</td>
              </tr>
          </table></td>
          <td  width="168px" height="112px"><table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
              <tr>
                <td height="38" colspan="2"><div align="center">
                  <input name="item12" type="text" id="item18" size="8" maxlength="8">
                </div></td>
              </tr>
              <tr>
                <td width="42%" height="30">&nbsp;</td>
                <td width="58%" height="30">&nbsp;</td>
              </tr>
              <tr>
                <td  height="25%" colspan="2">&nbsp;</td>
              </tr>
          </table></td>
        </tr>
        <tr>
          <td  width="168px" height="112px"><table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
              <tr>
                <td height="38" colspan="2"><div align="center">
                  <input name="item13" type="text" id="item18" size="8" maxlength="8">
                </div></td>
              </tr>
              <tr>
                <td width="42%" height="30">&nbsp;</td>
                <td width="58%" height="30">&nbsp;</td>
              </tr>
              <tr>
                <td  height="25%" colspan="2">&nbsp;</td>
              </tr>
          </table></td>
          <td  width="168px" height="112px"><table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
              <tr>
                <td height="38" colspan="2"><div align="center">
                  <input name="item14" type="text" id="item18" size="8" maxlength="8">
                </div></td>
              </tr>
              <tr>
                <td width="42%" height="30">&nbsp;</td>
                <td width="58%" height="30">&nbsp;</td>
              </tr>
              <tr>
                <td  height="25%" colspan="2">&nbsp;</td>
              </tr>
          </table></td>
          <td  width="168px" height="112px"><table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
              <tr>
                <td height="38" colspan="2"><div align="center">
                  <input name="item15" type="text" id="item18" size="8" maxlength="8">
                </div></td>
              </tr>
              <tr>
                <td width="42%" height="30">&nbsp;</td>
                <td width="58%" height="30">&nbsp;</td>
              </tr>
              <tr>
                <td  height="25%" colspan="2">&nbsp;</td>
              </tr>
          </table></td>
          <td  width="168px" height="112px"><table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
              <tr>
                <td height="38" colspan="2"><div align="center">
                  <input name="item16" type="text" id="item18" size="8" maxlength="8">
                </div></td>
              </tr>
              <tr>
                <td width="42%" height="30">&nbsp;</td>
                <td width="58%" height="30">&nbsp;</td>
              </tr>
              <tr>
                <td  height="25%" colspan="2">&nbsp;</td>
              </tr>
          </table></td>
        </tr>
        <tr>
          <td  width="168px" height="112px"><table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
              <tr>
                <td height="38" colspan="2"><div align="center">
                  <input name="item17" type="text" id="item18" size="8" maxlength="8">
                </div></td>
              </tr>
              <tr>
                <td width="42%" height="30">&nbsp;</td>
                <td width="58%" height="30">&nbsp;</td>
              </tr>
              <tr>
                <td  height="25%" colspan="2">&nbsp;</td>
              </tr>
          </table></td>
          <td  width="168px" height="112px"><table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
              <tr>
                <td height="38" colspan="2"><div align="center">
                  <input name="item18" type="text" id="item18" size="8" maxlength="8">
                </div></td>
              </tr>
              <tr>
                <td width="42%" height="30">&nbsp;</td>
                <td width="58%" height="30">&nbsp;</td>
              </tr>
              <tr>
                <td  height="25%" colspan="2">&nbsp;</td>
              </tr>
          </table></td>
          <td  width="168px" height="112px"><table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
              <tr>
                <td height="38" colspan="2"><div align="center">
                  <input name="item19" type="text" id="item18" size="8" maxlength="8">
                </div></td>
              </tr>
              <tr>
                <td width="42%" height="30">&nbsp;</td>
                <td width="58%" height="30">&nbsp;</td>
              </tr>
              <tr>
                <td  height="25%" colspan="2">&nbsp;</td>
              </tr>
          </table></td>
          <td  width="168px" height="112px"><table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0" bordercolor="000000">
              <tr>
                <td height="38" colspan="2"><div align="center">
                  <input name="item20" type="text" id="item18" size="8" maxlength="8">
                </div></td>
              </tr>
              <tr>
    
        </tr>
      </table>
      <p align="center">
        <input type="submit" name="Submit" value="Submit">
      </p>
    </form>
    </body>
    </html>
    <%
    RS_NumCheck1.Close()
    Set RS_NumCheck1 = Nothing
    %>

  • #4
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Instead of the popup.asp page popping up in a new window. You could load it into an iframe with a height and with of 0 (ie invisible) and change any references from opener to parent (in popup.asp)

    This would work well, and is more fully cross-browser supported than other methods, however you have so many checks needing to be done on the one page that it would be cleaner and more efficient to do the validation when the form gets posted. I know this isnt what you are looking for as a positive answer, but in this case I would suggest it. To make some 30 page requests each time querying the database is pretty time consuming, you can use SQL to do this much more efficiently.

    What you are asking is quite tricky if one is not familiar with the programming languages being used. I would suggest checking the form with javascript that the form fields have something typed in them in the right format when it is submitted, but as for checking the database 30 odd times on the one page - i'd be inclined to steer clear of it.

    m_n
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •