WebFormSubmitter Class

Imports System.Web

Imports System.Net

Imports System.IO

Public Class WebFormSubmitter

    'https://stackoverflow.com/questions/793755/how-to-fill-forms-and-submit-with-webclient-in-c-sharp

    Public Function submit(ByVal address As String,

                                  ByVal values As Dictionary(Of String, String)) As String

        Dim encoding As New UTF8Encoding

        Dim postData As String = getPostData(values:=values)

        Dim data() As Byte = encoding.GetBytes(postData)

        Dim request = CType(WebRequest.Create(address), HttpWebRequest)

        request.Method = "POST"

        request.ContentType = "application/x-www-form-urlencoded"

        request.ContentLength = data.Length

        'https://stackoverflow.com/questions/10205854/error-the-remote-server-returned-an-error-401-unauthorized

        request.UseDefaultCredentials = True

        request.PreAuthenticate = True

        request.Credentials = CredentialCache.DefaultCredentials

        Dim newStream = request.GetRequestStream()

        newStream.Write(data, 0, data.Length)

        newStream.Close()

        Dim response = request.GetResponse()

        Dim responseStream = response.GetResponseStream()

        Dim responseReader = New StreamReader(responseStream)

        Return responseReader.ReadToEnd()

    End Function

    Private Function getPostData(ByVal values As Dictionary(Of String, String)) As String

        Dim postDataPairList As New List(Of String)

        For Each anEntry In values

            postDataPairList.Add(anEntry.Key & "=" & HttpUtility.UrlEncode(anEntry.Value))

        Next

        Return String.Join(separator:="&", values:=postDataPairList)

    End Function

End Class

WebFormSubmitter Example

Dim dict As New Dictionary(Of String, String)

                dict.Add("ip", Button1555.Label)

                dict.Add("cidr", "/32")

                dict.Add("send", "submit")

                dict.Add("requestor_show_to_user", Replace(Environment.UserName, Environment.UserDomainName & "\", ""))

                Dim webform As New WebFormSubmitter

                Dim response As String = webform.submit("http://cnn/it/ipblock/add-dev.asp", dict)

                Dim frmWeb As New Form2

                frmWeb.WebBrowser1.DocumentText = response

                frmWeb.Show()

.

jQuery require another field if radio button is clicked

<body>

    <form action="" method="post">

        <label for="required_later">Required if Option2 selected</label>

        <input type="text" name="text_input_field" id="required_later" disabled><br>

        <input type="radio" id="option1" name="radio_options" value="option1">

        <label for="option1">Option1</label><br>

        <input type="radio" id="option2" name="radio_options" value="option2">

        <label for="option2">Option2</label><br>

        <input type="submit" name="submit" value="Submit">

    </form>

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

    <script>

        $("#option1").click(function() {

            $("#required_later").prop("required", false);

            $("#required_later").prop("disabled", true);

        });

        $("#option2").click(function() {

            $("#required_later").prop("required", true);

            $("#required_later").prop("disabled", false);

            $("#required_later").focus();

        });

    </script>

</body>


https://teamtreehouse.com/community/how-to-require-fields-if-a-certain-radio-button-is-checked