Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: Duplication validation before submittal


Message #1 by "Paul David Jacobs" <jacobspd@g...> on Fri, 14 Feb 2003 05:44:50 -0600
Hi All,
I am trying to create a page that adds a product to the database.  First
of all I want to check each box to see if it has input, if not flag an
error as a MsgBox window.  Once the form is completed then a check is
performed before submittal that checks one particular field for
duplication.  If a duplicate is found, it flags another Error in a
MsgBox.  Only after all the validation is complete then the information
of the form is passed on to another page and entered into the database.

See my code so far:
<script language=3D"vbscript">
<!--
SUB btnSubmit_OnClick()
  IF document.adpform.txtModel.value =3D "" THEN
    MsgBox "Falta Modelo.", 0, "Agregar Producto - Error."
  ELSEIF document.adpform.txtDescription.value =3D "" THEN
    MsgBox "Falta Descripci=F3n.", 0, "Agregar Producto - Error"
  ELSEIF document.adpform.txtPrice.value =3D "" THEN
    MsgBox "Falta Precio.", 0, "Agregar Producto - Error"
  ELSEIF document.adpform.txtElite.value =3D "" THEN
    MsgBox "Falta Elite.", 0, "Agregar Producto - Error"
  ELSEIF document.adpform.txtProspectus.value =3D "" THEN
    MsgBox "Falta Prospecto.", 0, "Agregar Producto - Error"
  ELSEIF document.adpform.txtNoElite.value =3D "" THEN
    MsgBox "Falta No-Elite.", 0, "Agregar Producto - Error"
  ELSEIF document.adpform.txtRegular.value =3D "" THEN
    MsgBox "Falta Precio m=EDnimo sugerido a usuario final.", 0, 
"Agregar
Producto - Error"
  ELSEIF document.adpform.txtSupplier.value =3D "" THEN
    MsgBox "Falta Proveedor.", 0, "Agregar Producto - Error"
  ELSE
    varModel =3D Trim(Request.Form("txtModel"))
  
    Dim rs, action, dbDir, strSQL
    
    SET DbConn =3D Server.CreateObject("ADODB.Connection")
    DbConn.Open "DSN=3Dsii"
    
    strSQL =3D "SELECT * FROM Compras WHERE Model =3D '" & varModel & 
"'"
    SET rs =3D DbConn.Execute(strSQL)
    IF NOT(rs.BOF and rs.EOF) THEN
      MsgBox "Modelo ya existe.", 0, "Agregar Producto - Error"
    ELSE
      CALL adpform.submit()
    END IF
  END IF
END SUB
//-->
</script>

The problem I have here is that you get maybe the first Msgbox because I
haven't typed in information, but when I click the 'OK' button on the
Msgbox the form is submitted and the information is added to the
database.  What I want to do is stop the submittal in it tracks if any
error is found, instead of submitting the information.

Please could someone tell me what I am doing wrong...
With many thanks for all you assistance and help

Paul D. Jacobs
Web Applications Developer and Information Systems Manager
jacobspd@g...
  _____ 

Servicios Interactivos Internacionales S.A. de C.V.
Via Ceti #56, Fracc Luis Enrique Erro,
Planetario Lindavista,
C.P 07730
M=E9xico D.F.



Message #2 by "Andrew Webster" <y5yxy@y...> on Fri, 14 Feb 2003 18:59:31
Well you could either do an Exit Sub immediately after the call to each 
MsgBox function, or because I like single exit points from functions, you 
could set a flag at the start of the routine (bErrorFound = false) and 
then change the state of the flag after each MsgBox function call 
(bErrorFound = true). You then do a check for this before calling the 
submit like this:
if not bErrorFound then
adpform.submit()
end if

Hope it helps...

Cheers
Andrew Webster
RedHat Solutions Ltd




> Hi All,
I am trying to create a page that adds a product to the database.  First
of all I want to check each box to see if it has input, if not flag an
error as a MsgBox window.  Once the form is completed then a check is
performed before submittal that checks one particular field for
duplication.  If a duplicate is found, it flags another Error in a
MsgBox.  Only after all the validation is complete then the information
of the form is passed on to another page and entered into the database.

See my code so far:
<script language=3D"vbscript">
<!--
SUB btnSubmit_OnClick()
  IF document.adpform.txtModel.value =3D "" THEN
    MsgBox "Falta Modelo.", 0, "Agregar Producto - Error."
  ELSEIF document.adpform.txtDescription.value =3D "" THEN
    MsgBox "Falta Descripci=F3n.", 0, "Agregar Producto - Error"
  ELSEIF document.adpform.txtPrice.value =3D "" THEN
    MsgBox "Falta Precio.", 0, "Agregar Producto - Error"
  ELSEIF document.adpform.txtElite.value =3D "" THEN
    MsgBox "Falta Elite.", 0, "Agregar Producto - Error"
  ELSEIF document.adpform.txtProspectus.value =3D "" THEN
    MsgBox "Falta Prospecto.", 0, "Agregar Producto - Error"
  ELSEIF document.adpform.txtNoElite.value =3D "" THEN
    MsgBox "Falta No-Elite.", 0, "Agregar Producto - Error"
  ELSEIF document.adpform.txtRegular.value =3D "" THEN
    MsgBox "Falta Precio m=EDnimo sugerido a usuario final.", 0, 
"Agregar
Producto - Error"
  ELSEIF document.adpform.txtSupplier.value =3D "" THEN
    MsgBox "Falta Proveedor.", 0, "Agregar Producto - Error"
  ELSE
    varModel =3D Trim(Request.Form("txtModel"))
  
    Dim rs, action, dbDir, strSQL
    
    SET DbConn =3D Server.CreateObject("ADODB.Connection")
    DbConn.Open "DSN=3Dsii"
    
    strSQL =3D "SELECT * FROM Compras WHERE Model =3D '" & varModel & 
"'"
    SET rs =3D DbConn.Execute(strSQL)
    IF NOT(rs.BOF and rs.EOF) THEN
      MsgBox "Modelo ya existe.", 0, "Agregar Producto - Error"
    ELSE
      CALL adpform.submit()
    END IF
  END IF
END SUB
//-->
</script>

The problem I have here is that you get maybe the first Msgbox because I
haven't typed in information, but when I click the 'OK' button on the
Msgbox the form is submitted and the information is added to the
database.  What I want to do is stop the submittal in it tracks if any
error is found, instead of submitting the information.

Please could someone tell me what I am doing wrong...
With many thanks for all you assistance and help

Paul D. Jacobs
Web Applications Developer and Information Systems Manager
jacobspd@g...
  _____ 

Servicios Interactivos Internacionales S.A. de C.V.
Via Ceti #56, Fracc Luis Enrique Erro,
Planetario Lindavista,
C.P 07730
M=E9xico D.F.



Message #3 by "Paul David Jacobs" <jacobspd@g...> on Fri, 14 Feb 2003 13:52:35 -0600
Hi,

I have now changed the code as follows:

<script language=3D"vbscript">
<!--
SUB btnSubmit_OnClick()
bErrorFound =3D false
  IF document.adpform.txtModel.value =3D "" THEN
    MsgBox "Falta Modelo.", 0, "Agregar Producto - Error."
    bErrorFound =3D true
  ELSEIF document.adpform.txtDescription.value =3D "" THEN
    MsgBox "Falta Descripci=F3n.", 0, "Agregar Producto - Error"
    bErrorFound =3D true
  ELSEIF document.adpform.txtPrice.value =3D "" THEN
    MsgBox "Falta Precio.", 0, "Agregar Producto - Error"
    bErrorFound =3D true
  ELSEIF document.adpform.txtElite.value =3D "" THEN
    MsgBox "Falta Elite.", 0, "Agregar Producto - Error"
    bErrorFound =3D true
  ELSEIF document.adpform.txtProspectus.value =3D "" THEN
    MsgBox "Falta Prospecto.", 0, "Agregar Producto - Error"
    bErrorFound =3D true
  ELSEIF document.adpform.txtNoElite.value =3D "" THEN
    MsgBox "Falta No-Elite.", 0, "Agregar Producto - Error"
    bErrorFound =3D true
  ELSEIF document.adpform.txtRegular.value =3D "" THEN
    MsgBox "Falta Precio m=EDnimo sugerido a usuario final.", 0, 
"Agregar
Producto - Error"
    bErrorFound =3D true
  ELSEIF document.adpform.txtSupplier.value =3D "" THEN
    MsgBox "Falta Proveedor.", 0, "Agregar Producto - Error"
    bErrorFound =3D true
  ELSE
    varModel =3D document.adpform.txtModel.value

    Dim rs, action, dbDir, strSQL

    SET DbConn =3D Server.CreateObject("ADODB.Connection")
    DbConn.Open "DSN=3Dsii"
    
    strSQL =3D "SELECT * FROM Compras WHERE Model =3D '" & varModel & 
"'"
    SET rs =3D DbConn.Execute(strSQL)
    IF NOT(rs.BOF and rs.EOF) THEN
      MsgBox "Modelo ya existe.", 0, "Agregar Producto - Error"
      bErrorFound =3D true
    END IF
  END IF
  IF NOT bErrorFound THEN
    adpform.submit()
  END IF
END SUB
//-->
</script>

However I am now getting a failure which I believe has something to do
with running server-side scripting and client-side scripting in the
wrong places or running ASP code inside <script> tags.  I am getting the
following error:

Object required: 'Server' on line 45 char 5 which is the following line
of the code:

    SET DbConn =3D Server.CreateObject("ADODB.Connection")

Any ideas why this is failing and how I can fix it, because I am at a
loss right now..

With many thanks for your continued assistance and time,

Paul D. Jacobs
Web Applications Developer and Information Systems Manager
jacobspd@g...
  _____ 

Servicios Interactivos Internacionales S.A. de C.V.
Via Ceti #56, Fracc Luis Enrique Erro,
Planetario Lindavista,
C.P 07730
M=E9xico D.F.


-----Original Message-----
From: Andrew Webster [mailto:y5yxy@y...]
Sent: Friday, February 14, 2003 7:00 PM
To: ASP Web HowTo
Subject: [asp_web_howto] Re: Duplication validation before submittal

Well you could either do an Exit Sub immediately after the call to each
MsgBox function, or because I like single exit points from functions,
you
could set a flag at the start of the routine (bErrorFound =3D false) and 

then change the state of the flag after each MsgBox function call
(bErrorFound =3D true). You then do a check for this before calling the
submit like this:
if not bErrorFound then
adpform.submit()
end if

Hope it helps...

Cheers
Andrew Webster
RedHat Solutions Ltd




> Hi All,
I am trying to create a page that adds a product to the database.  First
of all I want to check each box to see if it has input, if not flag an
error as a MsgBox window.  Once the form is completed then a check is
performed before submittal that checks one particular field for
duplication.  If a duplicate is found, it flags another Error in a
MsgBox.  Only after all the validation is complete then the information
of the form is passed on to another page and entered into the database.

See my code so far:
<script language=3D3D"vbscript">
<!--
SUB btnSubmit_OnClick()
  IF document.adpform.txtModel.value =3D3D "" THEN
    MsgBox "Falta Modelo.", 0, "Agregar Producto - Error."
  ELSEIF document.adpform.txtDescription.value =3D3D "" THEN=3D20
    MsgBox "Falta Descripci=3DF3n.", 0, "Agregar Producto - Error"
  ELSEIF document.adpform.txtPrice.value =3D3D "" THEN=3D20
    MsgBox "Falta Precio.", 0, "Agregar Producto - Error"
  ELSEIF document.adpform.txtElite.value =3D3D "" THEN=3D20
    MsgBox "Falta Elite.", 0, "Agregar Producto - Error"
  ELSEIF document.adpform.txtProspectus.value =3D3D "" THEN=3D20
    MsgBox "Falta Prospecto.", 0, "Agregar Producto - Error"
  ELSEIF document.adpform.txtNoElite.value =3D3D "" THEN
    MsgBox "Falta No-Elite.", 0, "Agregar Producto - Error"
  ELSEIF document.adpform.txtRegular.value =3D3D "" THEN
    MsgBox "Falta Precio m=3DEDnimo sugerido a usuario final.", 0, =3D
"Agregar
Producto - Error"
  ELSEIF document.adpform.txtSupplier.value =3D3D "" THEN=3D20
    MsgBox "Falta Proveedor.", 0, "Agregar Producto - Error"
  ELSE
    varModel =3D3D Trim(Request.Form("txtModel"))
  =3D20
    Dim rs, action, dbDir, strSQL
    =3D20
    SET DbConn =3D3D Server.CreateObject("ADODB.Connection")
    DbConn.Open "DSN=3D3Dsii"
    =3D20
    strSQL =3D3D "SELECT * FROM Compras WHERE Model =3D3D '" & varModel 
& =3D
"'"
    SET rs =3D3D DbConn.Execute(strSQL)
    IF NOT(rs.BOF and rs.EOF) THEN
      MsgBox "Modelo ya existe.", 0, "Agregar Producto - Error"
    ELSE
      CALL adpform.submit()
    END IF
  END IF
END SUB
//-->
</script>

The problem I have here is that you get maybe the first Msgbox because I
haven't typed in information, but when I click the 'OK' button on the
Msgbox the form is submitted and the information is added to the
database.  What I want to do is stop the submittal in it tracks if any
error is found, instead of submitting the information.

Please could someone tell me what I am doing wrong...
With many thanks for all you assistance and help

Paul D. Jacobs
Web Applications Developer and Information Systems Manager
jacobspd@g...=3D20
  _____ =3D20

Servicios Interactivos Internacionales S.A. de C.V.
Via Ceti #56, Fracc Luis Enrique Erro,
Planetario Lindavista,
C.P 07730
M=3DE9xico D.F.




Message #4 by "Paul David Jacobs" <jacobspd@g...> on Fri, 14 Feb 2003 14:24:58 -0600
I have now changed the code as follows:

<script language=3D"vbscript">
<!--
SUB btnSubmit_OnClick()
bErrorFound =3D false
  IF document.adpform.txtModel.value =3D "" THEN
    MsgBox "Falta Modelo.", 0, "Agregar Producto - Error."
    bErrorFound =3D true
  ELSEIF document.adpform.txtDescription.value =3D "" THEN
    MsgBox "Falta Descripci=F3n.", 0, "Agregar Producto - Error"
    bErrorFound =3D true
  ELSEIF document.adpform.txtPrice.value =3D "" THEN
    MsgBox "Falta Precio.", 0, "Agregar Producto - Error"
    bErrorFound =3D true
  ELSEIF document.adpform.txtElite.value =3D "" THEN
    MsgBox "Falta Elite.", 0, "Agregar Producto - Error"
    bErrorFound =3D true
  ELSEIF document.adpform.txtProspectus.value =3D "" THEN
    MsgBox "Falta Prospecto.", 0, "Agregar Producto - Error"
    bErrorFound =3D true
  ELSEIF document.adpform.txtNoElite.value =3D "" THEN
    MsgBox "Falta No-Elite.", 0, "Agregar Producto - Error"
    bErrorFound =3D true
  ELSEIF document.adpform.txtRegular.value =3D "" THEN
    MsgBox "Falta Precio m=EDnimo sugerido a usuario final.", 0, 
"Agregar
Producto - Error"
    bErrorFound =3D true
  ELSEIF document.adpform.txtSupplier.value =3D "" THEN
    MsgBox "Falta Proveedor.", 0, "Agregar Producto - Error"
    bErrorFound =3D true
  ELSE
    varModel =3D document.adpform.txtModel.value

    Dim rs, action, dbDir, strSQL

    SET DbConn =3D Server.CreateObject("ADODB.Connection")
    DbConn.Open "DSN=3Dsii"
    
    strSQL =3D "SELECT * FROM Compras WHERE Model =3D '" & varModel & 
"'"
    SET rs =3D DbConn.Execute(strSQL)
    IF NOT(rs.BOF and rs.EOF) THEN
      MsgBox "Modelo ya existe.", 0, "Agregar Producto - Error"
      bErrorFound =3D true
    END IF
  END IF
  IF NOT bErrorFound THEN
    adpform.submit()
  END IF
END SUB
//-->
</script>

However I am now getting a failure which I believe has something to do
with running server-side scripting and client-side scripting in the
wrong places or running ASP code inside <script> tags.  I am getting the
following error:

Object required: 'Server' on line 45 char 5 which is the following line
of the code:

    SET DbConn =3D Server.CreateObject("ADODB.Connection")

Any ideas why this is failing and how I can fix it, because I am at a
loss right now..

With many thanks for your continued assistance and time,

Paul D. Jacobs
Web Applications Developer and Information Systems Manager
jacobspd@g...
  _____ 

Servicios Interactivos Internacionales S.A. de C.V.
Via Ceti #56, Fracc Luis Enrique Erro,
Planetario Lindavista,
C.P 07730
M=E9xico D.F.


-----Original Message-----
From: Andrew Webster [mailto:y5yxy@y...]
Sent: Friday, February 14, 2003 7:00 PM
To: ASP Web HowTo
Subject: [asp_web_howto] Re: Duplication validation before submittal

Well you could either do an Exit Sub immediately after the call to each
MsgBox function, or because I like single exit points from functions,
you
could set a flag at the start of the routine (bErrorFound =3D false) and 

then change the state of the flag after each MsgBox function call
(bErrorFound =3D true). You then do a check for this before calling the
submit like this:
if not bErrorFound then
adpform.submit()
end if

Hope it helps...

Cheers
Andrew Webster
RedHat Solutions Ltd




> Hi All,
I am trying to create a page that adds a product to the database.  First
of all I want to check each box to see if it has input, if not flag an
error as a MsgBox window.  Once the form is completed then a check is
performed before submittal that checks one particular field for
duplication.  If a duplicate is found, it flags another Error in a
MsgBox.  Only after all the validation is complete then the information
of the form is passed on to another page and entered into the database.

See my code so far:
<script language=3D3D"vbscript">
<!--
SUB btnSubmit_OnClick()
  IF document.adpform.txtModel.value =3D3D "" THEN
    MsgBox "Falta Modelo.", 0, "Agregar Producto - Error."
  ELSEIF document.adpform.txtDescription.value =3D3D "" THEN=3D20
    MsgBox "Falta Descripci=3DF3n.", 0, "Agregar Producto - Error"
  ELSEIF document.adpform.txtPrice.value =3D3D "" THEN=3D20
    MsgBox "Falta Precio.", 0, "Agregar Producto - Error"
  ELSEIF document.adpform.txtElite.value =3D3D "" THEN=3D20
    MsgBox "Falta Elite.", 0, "Agregar Producto - Error"
  ELSEIF document.adpform.txtProspectus.value =3D3D "" THEN=3D20
    MsgBox "Falta Prospecto.", 0, "Agregar Producto - Error"
  ELSEIF document.adpform.txtNoElite.value =3D3D "" THEN
    MsgBox "Falta No-Elite.", 0, "Agregar Producto - Error"
  ELSEIF document.adpform.txtRegular.value =3D3D "" THEN
    MsgBox "Falta Precio m=3DEDnimo sugerido a usuario final.", 0, =3D
"Agregar
Producto - Error"
  ELSEIF document.adpform.txtSupplier.value =3D3D "" THEN=3D20
    MsgBox "Falta Proveedor.", 0, "Agregar Producto - Error"
  ELSE
    varModel =3D3D Trim(Request.Form("txtModel"))
  =3D20
    Dim rs, action, dbDir, strSQL
    =3D20
    SET DbConn =3D3D Server.CreateObject("ADODB.Connection")
    DbConn.Open "DSN=3D3Dsii"
    =3D20
    strSQL =3D3D "SELECT * FROM Compras WHERE Model =3D3D '" & varModel 
& =3D
"'"
    SET rs =3D3D DbConn.Execute(strSQL)
    IF NOT(rs.BOF and rs.EOF) THEN
      MsgBox "Modelo ya existe.", 0, "Agregar Producto - Error"
    ELSE
      CALL adpform.submit()
    END IF
  END IF
END SUB
//-->
</script>

The problem I have here is that you get maybe the first Msgbox because I
haven't typed in information, but when I click the 'OK' button on the
Msgbox the form is submitted and the information is added to the
database.  What I want to do is stop the submittal in it tracks if any
error is found, instead of submitting the information.

Please could someone tell me what I am doing wrong...
With many thanks for all you assistance and help

Paul D. Jacobs
Web Applications Developer and Information Systems Manager
jacobspd@g...=3D20
  _____ =3D20

Servicios Interactivos Internacionales S.A. de C.V.
Via Ceti #56, Fracc Luis Enrique Erro,
Planetario Lindavista,
C.P 07730
M=3DE9xico D.F.





  Return to Index