p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Classic ASP Professional (http://p2p.wrox.com/forumdisplay.php?f=63)
-   -   Validation Radio Buttons (http://p2p.wrox.com/showthread.php?t=58134)

jonsey May 21st, 2007 07:55 AM

Validation Radio Buttons
 
I have a script that works great to see what radio button is checked and then looks to see if comment is filled in for that question.

Now I just need to see if all answers are checked and if not give an alert and set.focus to that radio button.

Ok got it to work but keeps going to the first element.

Code:

<script language="vbscript" for="btnSaveAudit" event="onclick">

    Dim strMessage, requiredComment, objComment

    For Each r In document.getElementsByTagName("input")

        If r.Type = "radio" Then

            If Not r.Checked Then

            Set objComment = document.getElementsByName(r.Name)(0)
                    strMessage = strMessage & "Questions must have a Yes/No answer." & vbCrLf
                    Set requiredComment = r
                    Exit For

        Else

                If Not IsNull(r.Value) And r.Value <= 0 Then

                    Set objComment = document.getElementsByName(Replace(r.Name, "Value", "Comment"))(0)

                    If Len(objComment.Value) < 5 Then

                        strMessage = strMessage & "Questions answered with 'No' require a Comment." & vbCrLf
                        Set requiredComment = r
                        Exit For

                    End If

                End If

            End If

        End If

    Next

    If Trim(strMessage) = "" Then
        Call frmPRAP.Submit()
    Else
        Alert strMessage
        Call objComment.Focus()
    End If
</script>

Anyone have any ideals on this [?]

Thanks
Jonsey

dshamim June 6th, 2007 11:48 PM

Actually, javascript can better be used to target this scenario

Blog:
http://dimaghkidahi.blogspot.com/


All times are GMT -4. The time now is 02:39 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.