[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VB and VBSCript

Posted on 2000-04-27
3
Medium Priority
?
312 Views
Last Modified: 2010-05-18
I'm building a web page which allows the user to add information into database, and then displays the orignal page with a message -- error or confirmation. I also want to change the "Add" button to "Update" button.

I wrote VBScript to make sure that the user must enter data in some text fields.

Could you please help me to solve the problem I have:

If I choose input type as "Submit" ( <INPUT TYPE="Submit" VALUE="Add" Name="cmdSubmit">),the following code won't work:
 
<Script Language = "VBScript">

  Dim TheForm

  Sub Window_OnLoad
     Set TheForm = Document.FormAddAgency
  End Sub

  Function IsFieldEmpty(field, mes)
      If Len(field.value) = 0 Then
           Alert Mes
           field.focus
           IsFieldEmpty = False
      Else
           IsFieldEmpty = True
      End If
   End Function


 Sub cmdSubmit_OnClick
   Set ChkField = TheForm.FullName
       If Not IsFieldEmpty(ChkField, "Please enter Agency Name" ) Then
           Exit Sub
        End If

        Set ChkField = TheForm.ShortName
        If Not IsFieldEmpty(ChkField, "Please enter Agency Short Name") Then
            Exit Sub
        End If
        TheForm.submit

   End Sub

</Script>

If I choose input ytpe as "button" (<INPUT TYPE="button" VALUE="Add" Name="cmdSubmit">), the following won't work properly:

Select Case Request("cmdSubmit")
    Case "Update"
         Session("MessageType") = "Update"
         Session("Message") = "The current agency """ & Request.Form("FullName") & """ has been updated."
     Case "Add"
         Session("MessageType") = "Add"
         Session("Message") = "New agency """ & Request.Form("FullName") & """ has been added."
    End Select


0
Comment
Question by:leeann
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
mdougan earned 300 total points
ID: 2756401
Do you call different OnClick procedures for the Add and Updates?

If I were you, I'd have a hidden field in the same form as the button, then, in the OnClick procedure, set the value of the hidden field to Add or Update depending on which button you clicked.  Then, instead of checking the value of cmdSubmit, you'd check the value of the hidden form field instead.

If you don't have a separate OnClick procedure, then I think you can pass a parameter to the OnClick procedure, and that Parm could be different for the Add and Update buttons.  Sorry, I don't have sample code for this, but it's pretty basic.
0
 

Author Comment

by:leeann
ID: 2756452
Thanks! Mdougan,

The part of the "Select Case" code is VB code, and the OnClick procedure is VBScript code is running in client side.

Could you please tell me how to pass the flag "Add" or"Update through the OnClick procedure to VB code which is running on web server machine?

0
 
LVL 18

Expert Comment

by:mdougan
ID: 2757953
Well, you didn't show all of your client side code, but say that you have your procedure:

Sub cmdADD_OnClick

      myform.MODE.Value = "Add"
     
   Set ChkField = TheForm.FullName
       If Not IsFieldEmpty(ChkField, "Please enter Agency Name" ) Then
           Exit Sub
        End If

        Set ChkField = TheForm.ShortName
        If Not IsFieldEmpty(ChkField, "Please enter Agency Short Name") Then
            Exit Sub
        End If
        TheForm.submit

   End Sub

Sub cmdUpdate_OnClick

      myform.MODE.Value = "Update"
     
   Set ChkField = TheForm.FullName
       If Not IsFieldEmpty(ChkField, "Please enter Agency Name" ) Then
           Exit Sub
        End If

        Set ChkField = TheForm.ShortName
        If Not IsFieldEmpty(ChkField, "Please enter Agency Short Name") Then
            Exit Sub
        End If
        TheForm.submit

   End Sub

Then further down in the client code:

<form name='myform'>
<INPUT TYPE="HIDDEN" NAME="MODE"
<INPUT TYPE="button" VALUE="Add" Name="cmdADD">
<INPUT TYPE="button" VALUE="Update" Name="cmdUPdate">
</form>

In your server code:

Select Case Request("MODE")
    Case "Update"
         Session("MessageType") = "Update"
         Session("Message") = "The current agency """ & Request.Form("FullName") & """ has been updated."
     Case "Add"
         Session("MessageType") = "Add"
         Session("Message") = "New agency """ & Request.Form("FullName") & """ has been added."
    End Select
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month18 days, 2 hours left to enroll

830 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