in my validation the required fields can change. I have an array (required) of input ids which are required. If the array contains the string 'All' then all inputs are required.
I'm trying to use JQuery.inArray() to determine if required.
function getIfRequired(id){
console.log("id: "+id);
console.log(required);
console.log("inarray: "+jQuery.inArray(required, 'All'));
if (jQuery.inArray(required, 'All') > -1){ return true; }
else if(jQuery.inArray(required, id) != -1){ return true; }
else{ return false; }
}
But it keeps returning '-1' (not found).
here are example log outputs:
id: clientname
["clientname", "sourceid", "clientcountry","clienttown", "clienttownid", "typeoflaw"]
inarray: -1
id: clientname
["All"]
inarray: -1
Why is it not working?
'All'instead ofid? Also, the first argument should be the value and the second the array.inArray(value, array). ;)