jQuery IF and 'Radio' value question [closed]
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();
}
});
精彩评论