JavaScript - Using Arrays To Count Individual Words
Similar TutorialsI need to loop the alphabet and numbers 0-9 to initialize a few thousand arrays. This is for my site and is truly needed. http://www.thefreemenu.com I currently have every array written out and it takes up to much space in my .js file. The majority of my variables are empty but necessary and need to be there (including empty) for my site to work properly. Question is the last part Here's where I'm at. Code: var NewVarLetterOrNum = "a"; eval("_oneofseveralnames_" + NewVarLetterOrNum + "='this part works';"); alert(_oneofseveralnames_a); This creates the variable _oneofseveralnames_a='this part works' Code: var newArrayLetterOrNum = "a"; eval("_oneofseveralnames_" + newArrayLetterOrNum + "= new Array();"); alert(_oneofseveralnames_a) This creates the Array _oneofseveralnames_a=new Array(); and all the values in the array are null, but, now a variable like _nl_a[1]='something' can be used elsewhere because the array exists. This is all that is necessary for now because I can probably set all the variables to be blank with something like Code: i=1 while(i<=20){ _oneofseveralnames_a[i]="1-20"; i++ } alert(_oneofseveralnames_[20]); So now you have what I came to understand in the first few hours. Now to the hard part : ( I can't make multiple array's dynamically. I dont' know if its because I don't understand loops or arrays or what and its very fustrating. As for any answer you might be so kind as to provide, if you could dumb it down that would be greatly appreciated. Code: var newArray =new Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z') i=1 while(i<=26){ eval("_nl_" + newArray[i] + "= new Array();"); i++ } alert(newArray[1]) // Is b, but alert(_nl_b) //I can't get _nl_b to exist, I tried everything including taking away the quotes around the letters in every test */ var _nl_a =new Array() var _img_a =new Array() var _h_a =new Array() var _r_a =new Array() var _m_a =new Array() var _yt_a =new Array() var _i_a =new Array() The above arrays are all the array _name_ parts I need but for example, a has 10 parts, a,p2_a,p3_a,.. p10_a. I need 10 pages for each letter of the alphabet and numbers 0-9 and a special all1, p2_all1 ... p10_all1. Overall 2200 arrays that need to be declared. Currently they are all written out. /* i am interested in using RaphaelJS for creating VML/SVG rounded corners etc, but unless i physically put the <script> right after the element to which it needs to be applied, i have to rely on the single DOM load() event. which causes a delay before any script is executed,...thus a FOUC (flash of unstyled content). i'm guessing there is no way to track when individual elements are loaded into the DOM via a CSS filter or similar, or another way around this other than having <script> in the body or just dealing the the load delay? thanks, Leon I want to use some scripts from http://www.dynamicdrive.com Most of them require pasting script in both the HEAD and BODY of the page. Now, the way my WordPress is set up (Egesto theme), is in individual pages, which I cannot find any way to edit their HEAD or BODY. The only HEAD and BODY sections I see are in the Editor section, where I can edit the overall header.php, but that effects every page, I think. Anyways, does anyone know how I can solve this? Thank you. I have a code that checks individual checkboxes with a value in my group checkbox. Works great except When my group checkbox value ="955, 957,1956" it checks box 956 as well. How would I fix that? <!DOCTYPE html> <html> <head> </head> <body> ///----------GROUP CHECKBOXES---------------------/// 1,2,3<input type="checkbox" value="1,2,3" onclick="checkBox(this)"/> 4,5,6<input type="checkbox" value="4,5,6" onclick="checkBox(this)"/> 7,8,9<input type="checkbox" value="7,8,9" onclick="checkBox(this)"/> 955,957,1956<input type="checkbox" value="955,957,1956" onclick="checkBox(this)"/> ///----------Individual Checkboxes------------/// <div id="targets"> 1<input type="checkbox" value="1"/> 2<input type="checkbox" value="2"/> 3<input type="checkbox" value="3"/> 4<input type="checkbox" value="4"/> 5<input type="checkbox" value="5"/> 6<input type="checkbox" value="6"/> 7<input type="checkbox" value="7"/> 8<input type="checkbox" value="8"/> 9<input type="checkbox" value="9"/> 955<input type="checkbox" value="955"/> 956<input type="checkbox" value="956"/> 957<input type="checkbox" value="957"/> 1956<input type="checkbox" value="1956"/> </div> <script type="text/javascript"> function checkBox(box){ var cbs=document.getElementById("targets").getElementsByTagName("input") if (box.checked){ for (i=0;i<cbs.length;i++){ if(cbs[i].type=="checkbox"&&box.value.indexOf(cbs[i].value)!=-1){ cbs[i].checked=true; } } } else { for (a=0;a<cbs.length;a++){ if(cbs[a].type=="checkbox"&&box.value.indexOf(cbs[a].value)!=-1){ cbs[a].checked=false; } } } } </script> </body> </html> So I am using JavaScript to make a table on a page and what I want to do is have the JavaScript create the table, and then allow the user to fill it with data. I have been able to make the JavaScript create the table, my question is how to reference the cells in my script that adds data to the cell. I want the users to be able to click a button an add data into different cells so i figured giving them each an Id and referring to that Id in the button is the best way to do it. How can I edit my code to give each cell a different Id? Or is there a better way of doing this? My table code looks like this (i have filled it with random data so it is not just a blank table). <code> <script type="text/javaScript"> window.onload = fnInit; function fnInit() { // Declare variables and create the header, footer, and caption. var oTable = document.createElement("TABLE"); var oTHead = document.createElement("THEAD"); var oTBodyam = document.createElement("TBODY"); var oTBodypm = document.createElement("TBODY"); var oTFoot = document.createElement("TFOOT"); var oCaption = document.createElement("CAPTION"); var oRow, oCell; var i, j; // Declare stock data that would normally be read in from a stock Web site. var heading = new Array(); heading[0] = ""; heading[1] = "Monday"; heading[2] = "Tuesday"; heading[3] = "Wednesday"; heading[4] = "Thursday"; heading[5] = "Friday"; var block = new Array(); block[0] = "8:30"; block[1] = "9:55"; block[2] = "11:20"; block[3] = "12:45"; block[4] = "2:10"; block[5] = "3:35"; block[6] = "5:00"; block[7] = "6:30"; var stock = new Array(); stock[0] = new Array(block[0],"88.625","85.50","85.81","99.54","55.46"); stock[1] = new Array(block[1],"102.75","97.50","100.063","49.54","55.46"); stock[2] = new Array(block[2],"56.125","54.50","55.688","99.54","55.46"); stock[3] = new Array(block[3],"71.75","69.00","69.00","99.54","55.46"); stock[4] = new Array(block[4],"71.75","69.00","69.00","99.54","55.46"); stock[5] = new Array(block[5],"71.75","69.00","69.00","99.54","55.46"); stock[6] = new Array(block[6],"71.75","69.00","69.00","99.54","55.46"); stock[7] = new Array(block[7],"71.75","69.00","69.00","99.54","55.46"); // Insert the created elements into oTable. oTable.appendChild(oTHead); oTable.appendChild(oTBodyam); oTable.appendChild(oTBodypm); oTable.appendChild(oTFoot); oTable.appendChild(oCaption); // Set the table's border width and colors. oTable.border=1; oTable.bgColor="lightslategray"; // Insert a row into the header and set its background color. oRow = document.createElement("TR"); oTHead.appendChild(oRow); oTHead.setAttribute("bgColor","lightskyblue"); // Create and insert cells into the header row. for (i=0; i<heading.length; i++) { oCell = document.createElement("TH"); oCell.innerHTML = heading[i]; oRow.appendChild(oCell); } // Insert rows and cells into bodies. for (i=0; i<stock.length; i++) { var oBody = (i<3) ? oTBodyam : oTBodypm; oRow = document.createElement("TR"); oBody.appendChild(oRow); for (j=0; j<stock[i].length; j++) { oCell = document.createElement("TD"); oCell.innerHTML = stock[i][j]; oRow.appendChild(oCell); } } </code> I am Gururaj. I have written a form in HTML which contains username,lastname,email,password and submit. I have written a javascript to validate this form [validate(username,lastname,email,password)]. On submit this javascript function will be called and hence form get validated. I am passing all the arguements(username,lastname,email and password) to the javascript function.. Is it possible to make me a code such that it should call an individual function for each field in the form.for ex:if i have not entered username, last name in the form and attempt to submit, only username arguement should be passed to the function as it comes first in the form. In other sense i want to validate individual text field validation of my form. So can anybody help me.It will be very needful to me. Hi everybody I have a problem I want a header that is a slideshow and use lightbox for other images. No I have this all working but not at the same time. If I use this code in this order only the first script that is the lightbox script works. PHP Code: <script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript" src="js/pirobox.js"></script> <script type="text/javascript"> $(document).ready(function(){ $().piroBox({ my_speed: 300, //animation speed bg_alpha: 0.5, //background opacity slideShow : 'true', // true == slideshow on, false == slideshow off slideSpeed : 3, //slideshow close_all : '.piro_close' // add class .piro_overlay(with comma)if you want overlay click close piroBox }); }); </script> <script src="http://code.jquery.com/jquery-latest.js"></script> <script src="js/jquery.cycle.all.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('.slideshow').cycle({ fx: 'scrollLeft', speed: 1000, timeout: 7000 }); }); </script> If I use this code so I switched the order only the slideshow works: PHP Code: <script src="http://code.jquery.com/jquery-latest.js"></script> <script src="js/jquery.cycle.all.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('.slideshow').cycle({ fx: 'scrollLeft', speed: 1000, timeout: 7000 }); }); </script> <script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript" src="js/pirobox.js"></script> <script type="text/javascript"> $(document).ready(function(){ $().piroBox({ my_speed: 300, //animation speed bg_alpha: 0.5, //background opacity slideShow : 'true', // true == slideshow on, false == slideshow off slideSpeed : 3, //slideshow close_all : '.piro_close' // add class .piro_overlay(with comma)if you want overlay click close piroBox }); }); </script> I also tried this: but then they both did not work PHP Code: <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript" src="js/jquery.cycle.all.min.js"></script> <script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript" src="js/pirobox.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('.slideshow').cycle({ fx: 'scrollLeft', speed: 1000, timeout: 7000 }); $().piroBox({ my_speed: 300, //animation speed bg_alpha: 0.5, //background opacity slideShow : 'true', // true == slideshow on, false == slideshow off slideSpeed : 3, //slideshow close_all : '.piro_close' // add class .piro_overlay(with comma)if you want overlay click close piroBox }); }); </script> Can you help me solve this problem so they both work? I am trying to work out how to use Google Chrome DevTools to simulate a timeout on a JavaScript file on my site. I can use the 'Toggle Device Mode' to introduce throttling but that doesn't target a specific script. Is there a way to do this with DevTools? I am using Chrome 38. Hello! I have an array of strings, like this: var strings= [ "car", "black", "word", "small", "paper", "doom", "elemental", "sword", "mouse" ]; Now i got a function newgame() and i wanna display random word from this array in rectangles gray styled... Here is the problem. I can make to display random words, but i dont know how i make this words with the css style together - rectangels around a char. But the words are different length so i dunno? When i press newgame button, i want for example to random a word from the array: for example word "paper" then i want it to be displayed like this [p] [a] [p] [e] [r], where [ ] are rectangels around the chars ( with the css style, like this: border: 1px solid #000; width:10px; background-color:gray; text-align:justify; padding: 5px 10px; i make a gray rectangle border around the char, but how can i make it work with random words? How can i make it work? Any help please! Hi Someone know any script for division of words into syllables? Regards stickers Is there any way to convert a number stored as a javascript variable into words? Something like... Code: var num=120394; then run that var through a function and have the output be: One hundred twenty thousand three hundred ninety four Any help would be great! I want to create a web form that can substitute words in a URL with the inputted values. I realize the form is easy in HTML, and that's about all I'm good for. But I think the substitution must be done by javascript. For example: example.com/whatever/XXX/YYY I want the form to be able to replace the "XXX" and "YYY" with inputted values of the form, then I want it to direct to that URL when I click the "submit" button. Or just output the new URL as a link, whichever is easier. I know this has to be very basic javascript that is easy to do but I know next to nothing about this kind of thing. Sorry for the noob question but hours of googling/trying to figure out basic javascript has left me at a loss still. Help greatly appreciated! I'm trying to find a much simpler way than this current script I am using to generate and print a random word. I don't want to have to name each word but instead just include a very large list of about 300,000 words that javascript uses to pull a random word out of. Can you please help me out?? The list of words I have is a straight list with no commas or anything. I am currently outputting to a text box, but I am looking to generate words according to users input. For example, a user wants 500 words starting with the letter "b" and is less than 5 characters long appended to the character "de." Any help would be awesome! Even a right direction. I'm also willing to pay some for such a script if need be. Thanks! Here's my code: Code: <SCRIPT LANGUAGE="JavaScript"> <!-- var NumberOfWords = 28 var words = new BuildArray(NumberOfWords) words[1] = "czarevitch" words[2] = "brightwork" words[3] = "verkrampte" words[4] = "protectrix" words[5] = "nudibranch" words[6] = "grandchild" words[7] = "newfangled" words[8] = "flugelhorn" words[9] = "mythologer" words[10] = "pluperfect" words[11] = "jellygraph" words[12] = "quickthorn" words[13] = "rottweiler" words[14] = "technician" words[15] = "cowpuncher" words[16] = "middlebrow" words[17] = "jackhammer" words[18] = "triphthong" words[19] = "wunderkind" words[20] = "dazzlement" words[21] = "jabberwock" words[22] = "witchcraft" words[23] = "pawnbroker" words[24] = "thumbprint" words[25] = "motorcycle" words[26] = "cryptogram" words[27] = "torchlight" words[28] = "bankruptcy" function BuildArray(size){ this.length = size for (var i = 1; i <= size; i++){ this[i] = null} return this } function PickRandomWord(frm) { var rnd = Math.ceil(Math.random() * NumberOfWords) // Display the word inside the text box frm.WordBox.value = words[rnd] } //--> </SCRIPT> Hi guys, Do you know a function for banning certain words being inputted by the user eg I want to stop a user uploading offensive words and code tags like <script>, <div> etc.. and messing with the site display Thanks I am trying to understand what this javascript function is trying to accomplish. Can anyone breifly describe what the function is doing? If you can do a break down that would be great for me to understand this a bit better. I apreciate any assistance! Code: /* Engagement Score */ s.eVar5=s.engagementScore('event31','s.pageName|products|1>s.events|event6|1>s.eVar3|competitiveMatrix.pdf|1>s.pageName|webLeadsForm:complete|1>s.events|purchase|1>s.events|event4|1>s.events|scView|1'); /* Engagement Score Tracking */ s.engagementScore = new Function("e","l","c",""); var A,B,C,D,E,F,G,H,I,J; I=J=''; A=s.split(l,'>'); B=A.length; E=c?c:'s_ES'; //D=value of cookie with name 'E' D=s.c_r(E); if(!D){ for(C=0;C<B;C++){ D=D+'0,'; } } D=s.split(D,','); for(C=0;C<B;C++){ F=s.split(A[C],'|'); G=eval(F[0]); if(D[C]==1){ I=I+'1,'; } else if(G!=undefined){ if(G.indexOf(F[1])>-1&&D[C]!=1){ s.events=s.apl(s.events,e,',',2); s.products=s.apl(s.products,';;;;'+e+'='+F[2],',',2); I=I+'1,'; J='+'+F[2]; } else { I=I+'0,'; } } else{ I=I+'0,'; } } s.c_w(E,I,0); return J; s.split=new Function("l","d",""+"var i,x=0,a=new Array;while(l){i=l.indexOf(d);i=i>-1?i:l.length;a[x"+"++]=l.substring(0,i);l=l.substring(i+d.length);}return a"); Sorry, not sure if I need Javascript for this so I posted it in the html forum as well I'm looking to create a simple page where a user can copy and paste a list of ingredients and then push a button to search that list for a number of key words. Key words: Amodimethicone, Trimethylsilylamodimethicone, Glycerin, Trideceth-12, Behenoxy, Bisamino, Aminoethyl, PG-Propyl, Phenylpropyl, Methicone, Cyclomethicone, Cyclopentasiloxane, Cyclohexasiloxane, Cyclopentasiloxane, Dimethiconol, Trimethylsiloxysilicate, Silicate, Siloxy, Trimethylolpropane, Diisostearoyl, Copolyol, Dodecylbenzenesulphonate, Diphenyl, silicone, Methicone, Simethicone, Trisiloxane, sulfate, Myreth, Lauryl, Laureth, Sulfonate, dodecylbenzenesulfonate, Xylenesulfonate, Ammonium, Isethionate, Sulfoacetate, Sarcosinate, Sulfosuccinate, Carboxylate, Taurate, glycinate I don't care how they are alerted if any of the key words match their ingredients pop up, highlight, whatever. *Incase anyone is wondering it is to search hair products for any form of silcones or sulfates since many people wish to avoid them but they come in many different forms. Thanks!! I have the 10000th word and I want to put the this symbols [ and this ] the beginning and end of words .. so my question is .. how do I put the symbol is simultaneously the 10000th word that is .. there is not any program that can do such ... please help .. example : [can] [you] [me] [and] [ask] [google] [yahoo] [and over 10000 ++ more] Hello, I wanted to know how can I go through all the text on a page and store a unique ocurrence of every word in a array. Just point me on the right direction if you may. Got lost in translation... Lg |