i have this script that i use in conjunction with my tabs, so that when the user switches tab, if there are selected checkboxes on the previous tab, they become unchecked (it helps me with my messaging system)
However, as you can see, the problem is that the line
var w = document.getElementsByTagName('input');
selects all the inputs, and it is causing all my textboxes etc… to turn into checkboxes when i change tab, is there anyway i can only select the checkboxes rather than the inputs?
var w = document.getElementsByTagName('input');
for(var i = 0; i < w.length; i++){
if(w[i].type='checkbox'){
w[i].checked = false;
};
};
Here is the code that changes removes the checked boxes, and here is the entire code that controls the entire tab procedure;
$(document).ready(function() {
//Default Action
$(".tab_content").hide(); //Hide all content
$("ul.tabs li").eq(<?php print "$eq_id";?>).addClass("active").show(); //Activate second tab
$(".tab_content").eq(<?php print "$eq_id";?>).show(); //Show second tab content
//On Click Event
$("ul.tabs li").click(function() {
var w = document.getElementsByTagName('input');
for(var i = 0; i < w.length; i++){
if(w[i].type='checkbox'){
w[i].checked = false;
};
};
$("ul.tabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active content
return false;
});
});
Thanks for any and all help
since you’re using jquery
The recommended way
or the two deprecated ways
Also you are changing them into checkboxes in the following statement
if you just use jQuery.. you will only need the selector and can remove the if statement all together
http://jsfiddle.net/wirey00/UFdza/
The above should work in jQuery 1.6+ but if you are still using an older library you can use the following
http://jsfiddle.net/wirey00/UFdza/1/
EDIT–
You can replace
with
Yes, as Raminson pointed out
:checkboxselector has been deprecated. It’s not recommended to use them but they still work