Solved

VB and VBSCript

Posted on 2000-04-27
3
306 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

732 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