Object Method Issue

Results 1 to 2 of 2

Thread: Object Method Issue

  1. #1
    Join Date
    Dec 1969

    Default Object Method Issue

    Does anyone know how I can validate a radio or checkbox selection in vbscript? Here is the code I have below and the error I am receiving:<BR>&#060;!--<BR> Option Explicit<BR> Sub DoSave()<BR> Dim fOk<BR> Dim strMsg<BR><BR> fOk = True<BR><BR> If Len(LTrim(frmNewEmployee.radioPCLaptop.value))=0 Then<BR> fOk = False <BR> strMsg = "Please select either PC or Laptop."<BR> frmNewEmployee.radioPCLaptop.Focus<BR> ElseIf Len(LTrim(frmNewEmployee.selectBudget.value))=0 Then<BR> fOk = False <BR> strMsg = "Please select if Laptop is either Budgeted or not."<BR> frmNewEmployee.selectBudget.Focus<BR> ElseIf Len(LTrim(frmNewEmployee.txtEmail.Value))=0 Then<BR> fOk = False <BR> strMsg = "E-mail Address is a required field."<BR> frmNewEmployee.txtEmail.Focus<BR> ElseIf InStr(frmNewEmployee.txtEmail.Value, "@")=0 Or _<BR> InStr(frmNewEmployee.txtEmail.Value, ".")=0 Then<BR> fOk = False <BR> strMsg = "The entered e-mail address is not " & _<BR> "valid." & Chr(10) & Chr(13) & "E-mail " & _<BR> "addresses must be in the form name@domain."<BR> frmNewEmployee.txtEmail.Focus<BR> End If<BR><BR> &#039; If no errors, then submit the form<BR> If fOK Then<BR> frmNewEmployee.Submit<BR> Else<BR> MsgBox strMsg, , "Form Validation Error"<BR> End If<BR> End Sub<BR>--&#062;<BR>&#060;/script&#062;<BR><BR>The error I am getting is:<BR>Object doesn&#039;t support this property or method:<BR>frmNewEmployee.radioPCLaptop.value<BR>< BR>Thanks for all your help.

  2. #2
    Join Date
    Dec 1969

    Default RE: Object Method Issue

    You don&#039;t show the form or the input field. Maybe the error is there. Maybe it is in how you call this function. Maybe maybe maybe...<BR><BR>Not to ask silly questions, but.... You *are* aware that by choosing VBS in the client you are limiting yourself to users who choose to run MSIE, aren&#039;t you? <BR><BR>OH! Just realized! This is a RADIO BUTTON???<BR><BR>Of COURSE it won&#039;t work! If you have two radio buttons with the same name, then you no longer have a *SINGLE* field with a single value! You now have an *ARRAY*. And you must figure out the value by processing the array.<BR><BR>Here is one way you could do it:<BR><BR>Function GetRadioValue( radioGroup )<BR>&nbsp; &nbsp; Dim i<BR>&nbsp; &nbsp; For i = 0 To radioGroup.length<BR>&nbsp; &nbsp; &nbsp; &nbsp; If radioGroup(i).checked Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GetRadioValue = Trim( radioGroup(i).value )<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Exit Function<BR>&nbsp; &nbsp; &nbsp; &nbsp; End If<BR>&nbsp; &nbsp; Next<BR>&nbsp; &nbsp; MsgBox "No radio button in group " & radioGroup.Name & " was selected"<BR>&nbsp; &nbsp; GetRadioValue = ""<BR>End Function<BR><BR>Then you can call it via:<BR><BR>If Len( GetRadioValue(frmNewEmployee.radioPCLaptop) ) = 0 Then ...<BR><BR>By making GetRadioValue into a function, you can use it over and over for any group of radio buttons.<BR><BR>Hmmm...come to think of it, I think that exactly the same function works for a group of checkboxes. You probably want to omit the MSGBOX call from the function, of course.<BR><BR>So you could rename it to GetGroupValue and use it for either?<BR><BR>I do *NOT* use VBS for client side scripting, so pardon me if there&#039;s a typo or two in there.<BR><BR>

Posting Permissions

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