Would it be possible to have a webpage with normal HTML, but make it so the user can highlight some text, click a button and make it perform a word count on the selected text and disply the number of words in an alert()?
I know how to do a regular word count where it splits at the " ", but is there a way to split it at " " and " " [space and double space] in the same code so it accounts for people that double space also?
One option that occurred to me is to loop through all nodes in the div and count the words in the nodeValue if it's a text node, or otherwise loop through the element's sub-nodes if it has them. You could do this recursively and therefore find all text nodes within the DIV and its sub-elements.The problem is this doesn't cover everything. Inputs and textareas have a value, not a nodeValue. You will want to ignore any "script" elements and perhaps others. Of course you can set up a list of exceptions and modify the algorithm a bit to allow for them.An attempt at the approach described so far is shown here: [URL]But what about select elements? Do you want the value or do you want the text inside the selected option? What if they're multi-select lists? etc.
What I'm designing is a page with many layers each containing an image, these layers are about 300x200px in size and are spread over a large space on the page, which will force the page to be about 5000x5000px in size. The user will then have to scroll around the page both horizontally and vertically in order to see these layers containing images.
However, if all of these layers with images are loaded when the user enters the page, the used bandwidth will be huge. So what I'm thinking is figuring out a way to only load the images/layers that are in the users view, so that when the user scrolls to a new spot on the page, the images in that area are loaded, but not before.
How can I achieve this?
I have a notion that I might need a function to check which x&y position the user is at, and then set the content of a layer when the user's view 'contains' that layer. Is this a good way to proceed, and which functions should I look at?
I need a count down clock that will count down 18 minutes and reset itself at the end. also i need a counter that increases by +1 every 18 minutes starting at 0.
I have basic JS knowledge. I am trying to organize a JS timer which counts down to a specific date. After the target date is meet the timer starts to count up. Can someone point me to a JS sample which executes this count-down+target-date+then-count-up theme?
I have a long paragraph and I have been asked to display words in red and green in such a way that that fist word should be red, 2nd word should be green, 3rd word should be red and 4th word should be green and so on. For example: this is just a sample.
ielementfrompoint () gets an element at a given position (x,y). how can I get a single word (if it exists) from a given position? to sum up i need this: f(x,y)=word ( or null - in case there is no word). x, y is given NOT obtained with some mouseover event.
and the mouse is hovering over the word "fox". Using javascript, is it possible to determine the word under the mouse *without* introducing additional elements such as an anchor?
I have what seems to be a robust, working word counter script. I post it here to benefit others that might want this in the future and so that if I ever lose my copy I can come back here to find it :) Some other scripts that I used for inspiration failed when confronted with whitespace before the string or miscalculated when encountering linefeeds and other non-space spaces, so I made mine better. Definition of words for this exercise is contiguous groups of characters separated by whitespace. Code:
This JavaScript is a "Word Filter". It is a type of form validator. When the user submits some text, the validator will check the text for words that has to be filtered.
The words that have to be filtered must be added to the array swear_words_arr. When the user types the text and hits the submit button, if the text contains any word that is present in the array swear_words_arr, the form will not be submitted.
The script can be used for validation of swear words etc.
<html> <head> <title>Word Filter</title>
<!--BEGIN WORD FILTER JAVASCRIPT--> <script language="JavaScript1.2">
How do I check if a certain word exists in a text box? For example, if I set the word to be found to "word1", if the text box is "This is word1", and alert would come up saying that "word1" was found.
I have a JS function that is susposed to toggle word wrap on and off in a textarea. It works fine in IE but does not work in FireFox or Opera.
Does anyone know what the trick is to get it to work in FF and Opera?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <script type="text/javascript">
[Code]....
Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.
You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
I have a web form. I use a simple function to generate a letter ouput based on the form fields and populate them into a word doc for printing. Below is a basic example, but you get the idea.
Note this is only intended to be used on IE8. As it stands, the ouput generates and formats exactly as I want bar two things:
1) Does anyone know how I can get some of the text to bold? I've tried everything I can think of (html tags, escape characters etc etc). Is there a way to open a word window in rtf perhaps?
2) Does anyone know how I can insert a small image (a signature in gif or jpg) into the document?
I can use a browser window instead of word, which formats, bolds, images etc, however I then get the issue of headers/footers when printing. I cannot disable headers everytime I want to print a letter, it's not practical.
Suppose I've made my range so that it covers a word, using range.expand('word'). Typically to add the next word, I would write range.moveEnd('word', 1). But this seems not to work in Webkit. Perhaps it should be implemented differently?
Don't know if there is one of these online, so I made me own. Simple function that outputs a number as words. First argument is the number, second argument is flag (default = false) that controls whether output is cardinal or ordinal - as in "one" or "first".
Goodness knows if I have the grammer correct, especially when the numbers get big. Enjoy!
LIMITS:
1) Doesn't work with WebTV or below NS 4. Changing the large literal array into a common array should fix that, but I didn't bother.
2) Converts number into an integer before wording number. So, no "one point forty-five" stuff. This function is a good start for anyone who wants to do that though.
3) Always returns, "zero" for 0. Couldn't find cardinal equivalent to "zero"... zeroeth?
/* Num2Word, ouputs written number in human language format ARGUMENTS: ----------- Nbr: num, the number to be worded. This number is converted into an integer. Crd: bol, flags whether output is cardinal or ordinal number. Cardinal is used when describing the order of items, like "first" or "second" place. */ function Num2Word(num,fmt) { //_ arguments num = Math.round(num).toString(); // round value if (num == 0) return 'zero' // if number given is 0, return and exit //_ locals // word numbers var wnums = [['hundred','thousand','million','billion','trillion','zillion'],['one','first','ten','','th'],['two','second','twen',0,0],['three','third','thir',0,0],['four','fourth',0,0,0],['five','fifth','fif',0,0],['six','sixth',0,0,0],['seven','seventh',0,0,0],['eight','eighth','eigh',0,0],['nine','ninth',0,0,0],['ten',],['eleven',],['twelve','twelfth'],['thirteen',],['fourteen',],['fifteen',],['sixteen',],['seventeen',],['eighteen',],['nineteen',]]; // digits outside triplets var dot = (num.length % 3) ? num.length % 3 : 3; // number of triplets in number var sets = Math.ceil(num.length/3); // result string, word as number var rslt = '' //_ convert every three digits for (var i = 0; i < sets; i++) { // for each set of triplets // capture set of numbers up to three digits var subt = num.substring((!i) ? 0 : dot + (i - 1) * 3,(!i) ? dot : dot + i * 3); if (subt != 0) { // if value of set is not 0... var hdec = (subt.length > 2) ? subt.charAt(0) : 0; // get hundreds digit var ddec = subt.substring(Math.max(subt.length - 2,0),subt.length); // get double digits var odec = subt.charAt(subt.length - 1); // get one's digit // hundreds digit if (hdec != 0) rslt += ' ' + wnums[hdec][0] + '-hundred ' + ((fmt && ddec == 0) ? 'th' : ''); // add double digit if (ddec < 20 && 9 < ddec) { // if less than 20... // add double digit word rslt += ' ' + ((fmt) ? ((wnums[ddec][1]) ? wnums[ddec][1] : wnums[ddec][0] + 'th') : wnums[ddec][0]); } else { // otherwise, add words for each digit... // add "and" for last set without a tens digits if ((0 < hdec || 1 < sets) && i + 1 == sets && 0 < ddec && ddec < 10) rslt += 'and ' // tens digit if (19 < ddec) rslt += wnums[ddec.charAt(0)][(wnums[ddec.charAt(0)][2]) ? 2 : 0] + ((i + 1 == sets && odec == 0 && fmt) ? 'tieth' : 'ty') + ((0 < odec) ? '-' : ' '); // one's digit if (0 < odec) rslt += wnums[odec][(i + 1 == sets && fmt) ? 1 : 0]; } // add place for set if (i + 1 < sets) rslt += ' ' + wnums[0][sets - i - 1] + ' ' // if not last set, add place } else if (i + 1 == sets && fmt) { // otherwise, if this set is zero, is the last set of the loop, and the format (fmt) is cardinal rslt += 'th' // add cardinal "th" } } //_ return result return rslt }
Test the result of various valies like so
for (var i = 0; i < 50; i++) { var x = Math.round(Math.random() * 5000000); document.write(x,' -> ' + Num2Word(x).bold(),'<BR>'); }
Use this function towards whatever means you deem necessary. Pease credit me, Bemi Faison, if you use this script.