Solved

VB and VBSCript

Posted on 2000-04-27
3
304 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 100 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

770 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