JavaScript - Count The Number Of Elements Who Display Block?
So never done this one before so I am having a bit of a time trying to figure this one out.
Say I have a list of LI element and only a few of them have a inline style of display block, the rest have a display of none. How would I go about looping through and dertmining the number of elements that have a display of block? Code: for(var m = 0; m < li.style.display.length; i++) { alert(m); }; The above is just crazy but where my mind melts.. Similar TutorialsI need to count how many elements of a certain class are visible. Its for a form and the error messages for the fields are hidden (by default) spans with the class 'errors'. I need my page to count how many of these elements are visible when the user clicks the submit button. Is this possible or should i try and attack it a new way? I have a function below where every time a question is submitted, it will add a new row in the table with a textbox which allows numbers entry only. My question is that I don't know how to code these features in this function: 1: I want the text box to be between 0 and 100, so if text box contains a number which is above 100, it will automatically change the number to the maximum number which is 100. Does any one know how to code this in my function below in javascript: Code: function insertQuestion(form) { var row = document.createElement("tr"); var cell, input; cell = document.createElement("td"); cell.className = "weight"; input = document.createElement("input"); input.name = "weight_" + qnum; input.onkeypress = "return isNumberKey(event)"; cell.appendChild(input); row.appendChild(cell); } Hi all I have a form with one or more DIV elements inside it. When I try to count form elements I get result=0? How is this possible? See the example: Code: <html> <head> <script language="javascript"> function Count() { alert(document.frm1.elements.length); for(i=0; i<document.frm1.elements.length; i++) { alert(document.frm1.elements[i].name); } } </script> </head> <body> <form id="frm1" name="frm1"> <div id="div1" name="div1">.</div> </form> <input type="button" onclick="Count();" /> </body> </html> If I put other element (textbox) inside the form, the count result is correct. Is DIV not an element?! How can I count one or more DIV and inner DIV's? Thanks for your help. Z. I would like to be able to write a function (or something) to count the number of rows in the table, I don't know how to do it, any help is appreciated.
What i mean is - If ive got a 100% width div, and a person set only his country and name (i want to display inline), if only 2 of them is set i want 1 to be floating left, and one right, BUT IF 3 ISSET (like Date of Birth) i want the CSS to change to margin left 30px to make a gap between each of them, and if 4 isset then 20px gap, and so on, (got 5 that can be displayed there). I guess you do it JS/JQUERY
I wish to know how I can count how many lines there are by searching the innerHTML of a div can anyone suggest how this can be done? also when the new line is added in my code it clears the content of all the existing fields if there was anything in them before the add link was clicked Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script type="text/javascript"><!-- function addmore() { // count existing boxes to find out next number to use. // ? document.getElementById('namesdiv').innerHTML += '<textarea name="name_added" cols="30" rows="2"></textarea><br>'; document.getElementById('addressesdiv').innerHTML += '<textarea name="address_added" cols="30" rows="2"></textarea><br>'; document.getElementById('mobilesdiv').innerHTML += '<textarea name="mobile_added" cols="30" rows="2"></textarea><br>'; } --></script> </head> <body> <form> <div style="width: 850px;"> <div id="namesdiv" style="float: left; padding-right: 10px;">Client's Names<br> <textarea name="name1" cols="30" rows="2"></textarea><br> <textarea name="name2" cols="30" rows="2"></textarea><br> <textarea name="name3" cols="30" rows="2"></textarea><br> <textarea name="name4" cols="30" rows="2"></textarea><br> <textarea name="name5" cols="30" rows="2"></textarea><br> </div> <div id="addressesdiv" style="float: left; padding-right: 10px;">Client's Addresses<br> <textarea name="address1" cols="30" rows="2"></textarea><br> <textarea name="address2" cols="30" rows="2"></textarea><br> <textarea name="address3" cols="30" rows="2"></textarea><br> <textarea name="address4" cols="30" rows="2"></textarea><br> <textarea name="address5" cols="30" rows="2"></textarea><br> </div> <div id="mobilesdiv" style="float: left;">Client's Mobile numbers<br> <textarea name="mobile1" cols="30" rows="2"></textarea><br> <textarea name="mobile2" cols="30" rows="2"></textarea><br> <textarea name="mobile3" cols="30" rows="2"></textarea><br> <textarea name="mobile4" cols="30" rows="2"></textarea><br> <textarea name="mobile5" cols="30" rows="2"></textarea><br> </div> </div> <br style="clear: both;"> <a href="" onClick="javascript:addmore(); return false;" >Add more</a> </form> </body> </html> Just wondering what the code is for a phone number to be displayed nn-nnnnnnnn for example: 67 43289482 current code is Code: var pn = document.contact_form.phonenum.value; if ((pn.length != 10) || (/[^0-9]/g.test(pn))) { // 10-digit phone number alert ( "Please fill in your 10-digit telephone number" ); return false; } So I've got my code ready to generate a random number between a certain range and printing it out in text. What I'm trying to accomplish with this code is to print the actual image as well as the text. I'm aware that there is an error in my document.write line, and that it's not the best solution. I was hoping for some suggestions to change/improve this last bit. Thanks in advance! Code: <html> <title>RANDOM IMAGE TO NUMBER RANGE</title> <body> <center> <script language="javascript" type="text/javascript"> var ranges = [ { from: 11, image: "image4.jpg" }, { from: 1, image: "image3.jpg" }, { from: -9, image: "image2.jpg" }, { from: -20, image: "image1.jpg" } ]; var random_num = (Math.round((Math.random()*41)+-20)); var image = "default"; for(var i = 0; i < ranges.length; ++i) { if(random_num >= ranges[i].from) { image = ranges[i].image; break; } } { document.write("Text: " + random_num + " Text, " + " Image: = " + image); { document.write('<img src="images/' + ranges[i].image); } } </script> <br></br> <div> CLICK <a href="javascript:history.go(0);">REFRESH or F5</a> FOR A RANDOM IMAGE on NUMBER-RANGE. </div> </center> </body> </html> When I used toFixed() method on a number, I thought that this method round a number to a specified approximation, but I got a surprising result, the number became string! 15.23689 .toFixed ( 2 ) ==> "15.24" So does it convert the number into string? I am trying to figure out how to make a random number I can plug into a script count down from that number at certain times of the day until it reaches 0. I would like it to reset itself at midnight every day. I'm trying to make it work with a script I found on here that resets itself at midnight every day. So instead of it counting down too fast, it would count down to the next number after a randomly generated number of minutes until it reaches 0. But it wouldn't necessarily have to end at 0 at midnight. It could go from 845 to 323 at the end of the day at a slower pace. Is that possible?
is there a way using .htaccess or some other means that we can block certain websites from appearing when we do a google search of my wife's name? We contacted google and they denied our request to have these websites blocked. My wife has her own website she uses for her business. There was an .htaccess editor website that I visited that created the code after I specified the url of the websites we wanted blocked. Will this work and if so, after creating the .htaccess file what do I do with it, that is where do I attach it/post it? please help. (this is the first time i've ever posted anything on a website. my wife and I are technophobes.)
Hello everyone... I need "No-Block PopUp Window" for my web site.. for example if users open my sites another sites show or opens for them.. even a full page site like full pages ads.. and it be like One time per hour or more.. I found some script like that but some of them being blocked by IE or other browsers.. if anyone has kinda this JS code.. Please share it.. Thanks a lot What is the code to stop people from viewing your source. Such as this site: http://bad-behavior.com (View The Source of That Site) I've searched the forums, and all I got was a bunch of "nothing can protect your source" I don't care about all of that. I want the code because: 1. Most people don't know how to view a source after it has been blocked 2. I think it's cool Hi All, Below is a block of data. I'm trying to figure out how to extract text from the block. As you will see, some lines will have answers, some will not. I thought about using split, however not every line has the same delimiters (eg. $), and I am unsure how to apply 2 different splits per line, the only constant is that every line has a line feed at the end. E.g: YourPersonTitle$Title : Mr In the example above, I need to pull out everything between $ and line feed, so the result is: Title : Mr basically, any line with an answer needs to be returned. There would be a maximum of about 100 lines. I am currently reading a primer on regular expressions, but would appreciate some help or a point in the right direction. Code: YourPersonTitle$Title : Mr YourPersonTitle$OtherTitle : YourPersonalDetails$Surname : Citizen YourPersonalDetails$FirstName : Joe YourPersonalDetails$OtherNames : YourPersonalDetailsDOB : 1.11.1900 YourPostalAddress$Address : 2 Road Street, Sydney YourPostalAddress$State : NSW YourPostalAddress$Postcode : 2200 YourPhoneEmail$HomePhone : 9999 7777 Hey. I'm working on a simple slideshow made with jQuery, and i need some help now. What i'm trying to do now, is to make it change image every X second. I know how to change image, but i'm kind of stuck trying to find out how to make it "do something" every Xth second... i hope you understand what i mean. Here's an example: (obviously not working..) Code: function slideSwitch() { //change image... } setInterval(slideSwitch, 5000); //make the function slideSwitch execute every 5th second. If anyone could help me out here, i'd really appreciate it! Also, is there any "else if" function in jQuery? Like in for example PHP, you can use "if", "else if" and "else".. like this: Code: if(){ }else if(){ }else { } So is there any function like that? I googled it, and i found out i have to use some kind of plugin for it to work? How do i use it? Thanks in advance, -Nike We have live chat set up on our website. We can monitor visitors on the site and see what they are viewing and how long they've been there. The problem is that many people from our company are on the site, and we don't want them to show up in the visitor monitoring area. Is there a way to add javascript that will block our own IP address from displaying in our visitor monitoring? The company we are paying for the live chat service doesn't have a solution for us. Thanks! Hey. I'm kind stuck here. I can't see what's wrong with this small set of code? Is there anything wrong? I'm trying to follow a tutorial at themeforest.net, but i'm getting both confused and frustrated as it doesn't do anything at all! Code: <!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 src="jquery-1.4.1.min.js" type="text/javascript"></script> <style type="text/css"> #box { height: 300px; width: 300px; background: #2367AB; } </style> <script type="text/javascript"> $(document).ready(function() { $('a').click(function() { $('box').fadeOut(1000); }); }); </script> </head> <body> <div id="box"></div> <a href="#">Click me!</a> </body> </html> Hi I am generating a report on submit click.Due to size of data query execution takes some time to display result, in mean time if user press reload button on browser toolbar consequently same query request going to database and the performance become slow down. I am able to restrict user from clicking F5 and ctrl+R button but not reload button. I there any way to handle event on reload button? or can we disable reload button on submit? Thanks in advance! |