开发者

jQuery IF and 'Radio' value question [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I have a code that doesn't gives you to submit the form until all the fields are filled.

Now i have one field that is hidden unless the user checks the "client" option on the radio below it.

I need to know how can i check if the radio value is "client" and only then to force them to fill it in.

Here is the code that i came across with (开发者_JAVA技巧the client part doesn't work while the normal fields are ok.):

jQuery(function(){

var defaultVal1 = jQuery("#appName").val();
var defaultVal2 = jQuery("#appID").val();
var defaultVal3 = jQuery("#aToken").val();
var cVal = jQuery("input[name='clientCheck']").value == "client";

jQuery(".button").click(function(e){

var newVal1 = jQuery("#appName").val(); 
var newVal2 = jQuery("#appID").val();   
var newVal3 = jQuery("#aToken").val();

    if(defaultVal1 === newVal1, defaultVal2 === newVal2, defaultVal3 === newVal3)
       {
           alert("Please fill out all the fields.");
           e.preventDefault();
       }
               if(cVal)
           {
              alert("You have selected a Client App - Please fill out the Client Name.");
              e.preventDefault();
           }

   });    

Also i would like to know if i can specify the fields that they didn't filled out on the alert message.

Thanks a lot.


jQuery(function(){


var defaultVal1 = jQuery("#appName").val();
var defaultVal2 = jQuery("#appID").val();
var defaultVal3 = jQuery("#aToken").val();
var cVal = jQuery('input:radio[name=cliencheck]:checked').val();

jQuery(".button").click(function(e){

 newVal1 = jQuery("#appName").val(); 
 newVal2 = jQuery("#appID").val();   
 newVal3 = jQuery("#aToken").val();
 cVal = jQuery('input:radio[name=cliencheck]:checked').val();

    if(!(newVal1===defaultVal1 ) || !(newVal1===defaultVal2 ) || !(newVal3===defaultVal3 ))
       {
           alert("Please fill out all the fields.");
           e.preventDefault();
       }         
       else if(cVal == 'client')
       {
              alert("You have selected a Client App - Please fill out the Client Name.");
              e.preventDefault();
       }

   }); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜