Split String in Javascript & if the string is not split then how we can check in js

If you are looking for ways to simplify the dynamic form fields on certain conditions met in the form. Then this post is for you.

I have done research & came up with this solution which can very easily solve this problem, but the only problem with this if there are error & if you enable the exceptions line then there will be 1000s of errors.

JavaScript Code

$(document).ready(function(){
setInterval(function(){
$(".active-popup").each(function(){
x = $(this).prop("checked");
v = $(this).val();
toggle = $(this).attr("popup-toggle");
if (typeof toggle == "string"){
toggle = toggle.split(",");
}
conditions = $(this).attr("popup-condition");
if (typeof conditions == "string"){
conditions = conditions.split(",");
}
if (typeof toggle == "object" && typeof conditions == "object"){
for(var g = 0;g<= toggle.length;g++){
if (v == conditions[g] ){
//show the toggle
$("#"+toggle[g]).show();
}else{
//hide the toggle
$("#"+toggle[g]).hide();
}
}
}else{
if (x == true ){
//show the toggle
$("#"+toggle).show();
}else{
//hide the toggle
$("#"+toggle).hide();
}
}
});
},1);
});

But just give it a try, it works 100% if you set all the configurations properly.

Leave a Reply

Your email address will not be published. Required fields are marked *

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.