Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hallo everyone this is my first time using jquery mobile the problem I am having is I need to do validation on certain fields to disable a button. But the fields can differ based on radio button selection. But my code is not working. Any help would be appreciated.



JavaScript
         $(document).ready(function () {

             if ($("input[name=radio1]").val() == "choice-2")
             {
                 if (
                  $("#txt3PRecipientName").val() == ""
                 || $("#txt3PRecipientSurname").val() == ""
                 || $("#txt3PRecipientId").val() == ""
                 || $("#txt3PRecipientId").val() == ""
                 || $("#txt3PRecipientNo").val() == ""
                 || $("#txtEmail").val() == ""
                 || $("#txtId").val() == ""
                 || $("#txtCompanyName").val() == ""
                 || $("#txtStreet").val() == ""
                 || $("#txtSearch").val() == ""
                 || $("#txtCity").val() == ""
                 || $("#txtPostal").val() == ""
                 )
                 {
                     $("#btnSubmit").attr("disabled", true)

                 }
             }
             else if ($("input[name=radio1]").val() == "choice-1")
             {
                 if (

                  $("#txtEmail").val() == ""
                 || $("#txtId").val() == ""
                 || $("#txtCompanyName").val() == ""
                 || $("#txtStreet").val() == ""
                 || $("#txtSearch").val() == ""
                 || $("#txtCity").val() == ""
                 || $("#txtPostal").val() == ""
                     )
                 {
                     $("#btnSubmit").attr("disabled", true)
                 }



             }


});
Posted
Updated 29-Sep-14 4:49am
v3

Use $.trim() (for e.g $.trim($("#txtEmail").val()) == "") to remove blank space.

replace code
JavaScript
$("input[name=radio1]").val() to $('input[name="radio1"]').val()
 
Share this answer
 
v2
just add required = "true" to all the controls that need to be checked
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900