JavaScript - Cycling Through Checkboxes
Hi Guys,
I'm currently working on a page working with separate categories and a whole lotta check boxes. My objective is to have one checkbox deselect the other checkboxes in its category without interfering with the rest. How would I go about doing this assuming the id tag is already in use and differs per tag? I was thinking about cycling through all checkbox tags and sorting them out via class but I'm looking for something possibly more efficient. Similar TutorialsI can get the code to open 'variouslinks()' when I click the 'Go HERE' link but I cannot get it to open them in a new window. I tried using HTML and JAVASCRIPT. Can someone please tell me what I am doing wrong???? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script> var variouslinks=new Array() variouslinks[0]="http://www.Facebook.com"; variouslinks[1]="http://www.Myspace.com"; variouslinks[2]="http://www.FriendFinder.com"; variouslinks[3]="http://www.AshleyMadison.com"; variouslinks[4]="http://www.Pets.com"; function variouslink(){ window.location=variouslinks[Math.floor(Math.various()*variouslinks.length)]; } function openNewWindow(){ var newWindow=window.open(this.getAttribute('href'), '_blank'); newWindow.focus(); return false;} </script> </head> <body> <a href="javascript:variouslink()" rel="nofollow" target="javascript:openNewWindow()">Go HERE</a> </body> </html> I've got a table in which I want to have certain elements changeable if the user presses a button. The elements are stored in an array and I want to cycle through them when the button is pressed. Here's a section of what I'm working with so far: Code: <tr> <td valign="top"> <dl> <script type="text/javascript"> var w=0; var s=0; var c=0; var slugga_replace_list = new Array("Slugga","Shoota","Shoota/Rokkit","Shoota/Skorcha","Twin-Linked Shoota"); var choppa_replace_list = new Array("Choppa","Big Choppa","Power Klaw"); var warboss_wargear = new Array(); warboss_wargear[0] = slugga_replace_list[s]; warboss_wargear[1] = choppa_replace_list[c]; warboss_wargear[2] = "Stikkbombz"; for (w=0; w<2; w++) { document.write("<dt><input type='button' name='subtract' value='-' onclick='subtract()'>"+warboss_wargear[w]+"<input type='button' name='add' value='+' onclick='add()'/></dt>"); } function add() { s++ return s; } function subtract() { s-- return s; } </script> </dl> </td> </tr> I've tried using the ++ and -- to change the value of s, but it's not changing the text. Am I in the neighborhood at least? Can somebody please explain why when the lines of code that are commented out are reintroduced that this code breaks instead of resulting in each of the four circles being a different color? Code: <!DOCTYPE HTML> <html> <head><title>Circles</title></head> <body> <canvas id="myCanvas" width="512" height="128" style="border:1px solid #c3c3c3;"> Your browser does not support the canvas element. </canvas> <script type="text/javascript"> var i=0; var axisX=128; var axisY=64; var radius=56; //var colors=[red, green, blue, yellow]; //var currentColor; function drawCircle(){ //currentColor=colors[i]; var c=document.getElementById("myCanvas"); var cxt=c.getContext("2d"); //cxt.fillStyle=currentColor; cxt.strokeStyle="black"; cxt.beginPath(); cxt.arc(axisX,axisY,radius,0,Math.PI*2,true); cxt.closePath(); cxt.fill(); cxt.stroke(); } for (i=0;i<4;i++){ drawCircle(); axisX=axisX+84; } </script> </body> </html> What am I doing wrong? Thank you! I basically want a random image to show up on my webpage and start scrolling through more images i've set to that list. Here's what I have thus far. However, It'll always start by bringing up the same image and then change to an error image: Code: <html> <head> <script type="text/javascript" language="javascript"> <!-- Hide script from old browsers adImages = new Array("http://i155.photobucket.com/albums/s298/Connorconway/Office_Season_6_Blu-Ray.jpg","http://i155.photobucket.com/albums/s298/Connorconway/Halloween_Blu_Ray.jpg") imgCt = adImages.length firstTime = true function rotate() { if (document.images) { if (firstTime) { thisAd = Math.floor((Math.random * imgCt)) firstTime = false } else { thisAd++ if (thisAd == imgCt) { thisAd = 0 } } document.myPicture.src=adImages [thisAd] setTimeout("rotate()", 3 * 1000) } } //--> End hiding script from old browsers </script> </head> <body onload="rotate()"> <img src="http://i155.photobucket.com/albums/s298/Connorconway/Office_Season_6_Blu-Ray.jpg" width="400" height="300" name="myPicture" alt="Ad Banner" /> </body> </html> Here's the Website I'm having problems on (So you can visually see what I mean - Under "TV ManiaX Home Page sub-heading): http://tvmaniax.myfastforum.org/index.html Thank you for any help you can give _________________ Dear Forum Members HI, I am no coder, however I am modifying my website and changing the slideshow to the one found on this website, most wonderful, the Cut & Paste JavaScript Slideshow( http://www.javascriptkit.com/script/.../jsslide.shtml ) I have it working now, and I have but one question, does the code include a way to limit the number of times that it cycles through the slides? So it just freezes on one photo after x number of cycles? many thanks, and happy holidays... have a simple calculator i made with checkboxes and some Js. the problem is that it does not work in FF. any idea how this can work for IE Safari AND FF Code: function getPrice(amount, boxName){ total = eval() ; checked = document.getElementById(boxName).checked if (checked){ total = parseFloat(form1.Total2.value) + parseFloat(amount); }else{ total = parseFloat(form1.Total2.value) - parseFloat(amount); } total.toFixed(2); form1.Total2.value = total document.getElementById("total").innerHTML = "Total $"+total; } Hi all. I have the following problem that I require a pointer with. I have a php variable named "$seatid" This could contain 1 or many entries. I have a page full of checkboxes named A1-8, B1-8, C1-8 etc to P1-8 I want a way of greying out the checkboxes on the page that relate to the values that are contained in the php variable. So they cannot be clicked. It would also like to change the colour of the cell that the check box is contained in. It is important that the checkboxes or at least the table that contain the checkboxes remain, as it represents the layout of a theatre. Cheers for your help All, I have the following code which validates a form has at least one checkbox checked before it submits it. However I want to make sure that there aren't more then 25 checked on the page. How can I do this? Code: function validate(field) { for (var i = 0; i < field.length; i++){ if(field[i].checked){ // if a field is checked form is submitted return true; } } alert("You need to have a check box selected to submit the form!"); return false; // if no fields are checked form not submitted } Thanks in advance! My form generates 1 to n records which contains check boxes. Based on some condition if I click a check box it has to check & disable some other check boxes automatically. I did it. But, at the same time if I un-check I have to un-check all the check boxes which were checked. Please let me know. Thanks a lot.
Good evening all, I have a bit of an issue with checkboxes - basically I need to allow only 1 selection and then have a comments box show when a checkbox is checked. I've gotten the comments box to show when the checkbox is checked but I can't seem to workout how to allow only one. I'd really like the user to be able to change their mind and make a different selection but only have 1 be selected at a time (sort of like radio buttons work). I know it would be much easier and probably better to use radio buttons but that isn't an option with this. (The actual HTML is produced using a style sheet in an application that I am interfacing with so all I can do is use the checkbox.) Here is the code I am using to show or hide the comments box. Code: function HideComments() { var a1 = document.getElementById("crmForm_answer1").checked; var a8 = document.getElementById("crmForm_answer8").checked; var a2 = document.getElementById("crmForm_answer2").checked; var a3 = document.getElementById("crmForm_answer3").checked; var a4 = document.getElementById("crmForm_answer4").checked; var a5 = document.getElementById("crmForm_answer5").checked; var a6 = document.getElementById("crmForm_answer6").checked; var a7 = document.getElementById("crmForm_answer7").checked; var a9 = document.getElementById("crmForm_answer9").checked; var a10 = document.getElementById("crmForm_answer10").checked; if(a1==true) { document.getElementById("crmForm_answer1_value").parentNode.parentNode.style.display = 'block'; } else document.getElementById("crmForm_answer1_value").parentNode.parentNode.style.display = 'none'; if(a8==true) { document.getElementById("crmForm_answer8_value").parentNode.parentNode.style.display = 'block'; } else document.getElementById("crmForm_answer8_value").parentNode.parentNode.style.display = 'none'; if(a2==true) { document.getElementById("crmForm_answer2_value").parentNode.parentNode.style.display = 'block'; } else document.getElementById("crmForm_answer2_value").parentNode.parentNode.style.display = 'none'; if(a3==true) { document.getElementById("crmForm_answer3_value").parentNode.parentNode.style.display = 'block'; } else document.getElementById("crmForm_answer3_value").parentNode.parentNode.style.display = 'none'; if(a4==true) { document.getElementById("crmForm_answer4_value").parentNode.parentNode.style.display = 'block'; } else document.getElementById("crmForm_answer4_value").parentNode.parentNode.style.display = 'none'; if(a5==true) { document.getElementById("crmForm_answer5_value").parentNode.parentNode.style.display = 'block'; } else document.getElementById("crmForm_answer5_value").parentNode.parentNode.style.display = 'none'; if(a6==true) { document.getElementById("crmForm_answer6_value").parentNode.parentNode.style.display = 'block'; } else document.getElementById("crmForm_answer6_value").parentNode.parentNode.style.display = 'none'; if(a7==true) { document.getElementById("crmForm_answer7_value").parentNode.parentNode.style.display = 'block'; } else document.getElementById("crmForm_answer7_value").parentNode.parentNode.style.display = 'none'; if(a9==true) { document.getElementById("crmForm_answer9_value").parentNode.parentNode.style.display = 'block'; } else document.getElementById("crmForm_answer9_value").parentNode.parentNode.style.display = 'none'; if(a10==true) { document.getElementById("crmForm_answer10_value").parentNode.parentNode.style.display = 'block'; } else document.getElementById("crmForm_answer10_value").parentNode.parentNode.style.display = 'none'; } Thanks in Advance Sam Hello, I have a form generated by mySQL and PHP, and inside the form (named 'UpdateDB') each line has checkboxes, like so: Code: <input type="checkbox" name="checkbox[]" value="96" onclick="highlight(this,'check_96')"> The onclick is to highlight the row, that works fine. However, I wrote a javascript function that toggles the select all the checkboxes or none. This is done by an image: Code: <img src="img/select.png" align="top"> <a href="#" onClick="togBox('updateDB');"><img src="img/all.png" name="listToggle" align="top"></a> Easy, right? So heres the Javascript function that the above image (the 'none' part) links to: Code: function togBox(form) { var myForm = document.forms[form]; document.listToggle.src=='http://gospeltruth.tv/admin/img/all.png' ? toggle = true : toggle = false; (toggle) ? document.listToggle.src='img/none.png' : document.listToggle.src='img/all.png'; for( var i=0; i < myForm.length; i++ ) { (toggle) ? myForm.elements[i].checked = 'checked' : myForm.elements[i].checked = ''; } } Its a brilliant function if I do say so myself, and this is what I dont get: two days ago, it was working fine, today, its not working at all. The image changes, but IE flags up the 'myForm.length' as an error. How was it working 2 days ago and not today, when I havent touched it? Can anybody advise why its not currently working? Thanks for your help, ~Chud37 irst post here, i'll try to be simple: I need to create a form where participants of a medical convention register to classes, each class lasts 3 hours, so a person who wants to attend to class starting at 10 am cannot register to 11 am, 12pm and 1pm classes, but he can register to 2pm and so on. There are 3 different classes per hour. i thought doing this using javascript, but i'm absolutely lost. Can you please give me a hint on how to do this? Thanks!! this is the part of the form that has the checkboxes. <form method="post" action="process.php"></form> <input type="checkbox" value="101" name="convention1"> 10 am: Cariovascular desease<br> <input type="checkbox" value="102" name="convention2"> 10 am: Changes on toracic surgeon<br> <input type="checkbox" value="103" name="convention3"> 10 am: New drugs on heart<br> <input type="checkbox" value="111" name="convention4"> 11 am: New drugs on heart (II)<br> <input type="checkbox" value="112" name="convention5"> 11 am: Dynamic process on blood pressure<br> <input type="checkbox" value="113" name="convention6"> 11 am: Aortic disease<br> <input type="checkbox" value="121" name="convention7"> 12 am: Pulmonar Pressure<br> <input type="checkbox" value="122" name="convention8"> 12 am: Open table<br> <input type="checkbox" value="131" name="convention9"> 1 pm: Neurological aspects on heart rate<br> <input type="checkbox" value="132" name="convention10"> 1 pm: Cardiovascular disease (II)<br> <input type="checkbox" value="133" name="convention11"> 1 pm: Mioresponse on heart failure<br> <input type="checkbox" value="141" name="convention12"> 2 pm<br> <input type="checkbox" value="142" name="convention13"> 2 pm<br> <input type="checkbox" value="143" name="convention14"> 2 pm<br> <input type="checkbox" value="151" name="convention15"> 3 pm<br> <input type="checkbox" value="152" name="convention16"> 3 pm<br> <input type="checkbox" value="153" name="convention17"> 3 pm<br> <input type="submit"></input> </form> This script works via "elem.checked" which is great for checkboxes (see http://javascript.internet.com/forms...heckboxes.html), but I need it to work with image buttons instead where there is no "checking" going on. Is this possible? I tried elem.onclick and elem.clicked but neither works. I don't know enough about onclick conditionals. Please help. Code: function UpdateCost() { var sum = 0; var gn, elem; for (i=0; i<4; i++) { gn = 'game'+i; elem = document.getElementById(gn); if (elem.checked == true) { sum += Number(elem.value); } } document.getElementById('totalcost').value = sum.toFixed(2); } tl;dr: Want to make the above work with <a onclick="UpdateCost()"><img></a>, not <input type="checkbox" onclick="UpdateCost()"> I am trying to get a link that when clicked it will check all the checkboxes in my form. My problem is that my values are stored in an array: <INPUT TYPE=\"checkbox\" name=\"emailArray[]\" value=\"$email\"> print"<br><a href=\"#\" onClick=\"checkAll()\">check all</a><br>"; Here is my javascript function : function checkAll(){ alert('hi'); var df = document.selectEmailForm.elements; for (var i = 0; i < df.length; i++) { if (df[i].name == "emailArray[]" ) { document.selectEmailForm.emailArray[i].checked=true; } } } Any ideas? Any help is greatly appreciated. Thanks for your time! Hello, today I am trying to allow a user to easily uncheck/check all checkboxes in a form by checking or unchecking a checkbox. The checkboxes would be in a form like so: Code: <form action="" method="post"> <input type="checkbox" name="checked[]" value="1"> <input type="checkbox" name="checked[]" value="2"> <input type="checkbox" name="checked[]" value="3"> <input type="checkbox" name="checked[]" value="4"> </form> I use an event handler to call a function: Code: <input type="checkbox" name="checkall" onchange="checkall('checked[]', this.checked)"> And here is the function: Code: function checkall(box_name, current_state) { all = document.getElementsByName(box_name); action = (current_state == "checked") ? "false" : "true"; for (i = 0; i < all.length; i++) { all[i].checked=action; } } The event handler should pass the name of the checkboxes and whether the "check all" checkbox is currently checked or not to the checkall() function. Nothing happens when I check/uncheck the "check all" function. Help? i'm using http://www.javascript-coder.com/html...lidation.phtml now I want to know how to validate a checkbox if i have <input type=checkbox id="c2" name=33>dd <input type=checkbox id="c2" name=33>ff.aa <input type=checkbox id="c2" name=33>ddd is it correct to have them all with the same id and how do I validate it using this validation routine? (or if this one doesn't work is there a specific validation functions -your can recommend that are easy to use for all different types of input) from a browser address bar command? say if a page has hundreds of checkboxes, and I needed to check them all, but only 2-3 should be left out, how do i input a browser command line, to check it all, so i will manually uncheck the 2 or 3 thats not needed?
I have a group of checkboxes named "list[]". I want to validate that at least one is checked. How can I do this?
Hi all, I have a form with a number of checkboxes. The 1st one is "Select All". When this checkbox is ticked I would like to disable all others. When the "Select All" checkbox is unticked, all checkboxes should be enabled. Can anyone tell me how to do this? is JQuery the preferred method these days? Thanks in advance Hello. How can you modify this code so that if you click a checkbox that is ALREADY CHECKED, it will remain checked? By the way, I have searched the web on how to do this and the general consensus seems to be "use radio buttons instead", but I would not like to use radio buttons. I would like to use checkboxes, I think they look better for what I am trying to do. Thanks for any help Code: <input type="checkbox" id="ckbox1" onclick="if(this.checked){ document.myform.ckbox1.checked=true; document.myform.ckbox2.checked=false; document.myform.ckbox3.checked=false;}" checked="checked" />Best Match <input type="checkbox" id="ckbox2" onclick="if(this.checked){ document.myform.ckbox1.checked=false; document.myform.ckbox2.checked=true; document.myform.ckbox3.checked=false;}" />All Words <input type="checkbox" id="ckbox3" onclick="if(this.checked){ document.myform.ckbox1.checked=false; document.myform.ckbox2.checked=false; document.myform.ckbox3.checked=true;}" />Exact Phrase |