JavaScript - Dynamic Search For A Stirng In Word Doumnets Using Javascript
Requirement:
In one folder for ex: C:\NewFolder , I have so many word documents in this folder. Now what I have to do is, need to search for any string and it should search for that string in all documents inside that folder and should show output as the name of the docs where it found (same like windows search output) and i should be able to open those docs. I want to do this using Javascript. I'm new to javascripting. Kindly help me Similar TutorialsThis example works fine to match a users input. Code: if ((word[0]=="my") && (word[1]=="name") && (word[2]=="is") && (input.search(/(john|paul|zack)/)!=-1) && (num_of_words== 4)) {document.result.result.value = "Well, nice to meet you "+word[3]+"."; return true;} However, can you do a search on what would be word[3] in the example above. Something like: word[3]=="(input.search(/(john|paul|zack)/)!=-1)" Thanks! Hi All, There is a code something like the one below which searches for a word on a page, highlights it and scrolls to it (which the code below can do). However, the code shown has an issue in firefox in so much as it stops looking once the search arrives at the input field if the field is above the text on page. However, by placing the the input field below the text on the page the search will find words as it should. If for testing the input field were placed in the middle of the page text, the search would work and find until it hits the input field and the field itself highlights but it won't search past the field. By chance a while back I did come across a forum in which a reply had some additional code which solved the issue and allowed the search to continue past the input field. However, I just remember the item and have no idea where I saw it or what the code was or even if it actually worked because at the time I was not actually looking for that and it was just a chance encounter. So the question is, has anyone any idea as to what that bit of code may have been? Martin. <input type="text" id="mytext" name="mytext" value="" size="20"> <input type="button" value="Find on page" onClick="findit()"> Code: <!-- var TRange=null; function findit () { var str= document.getElementById("mytext").value; if (parseInt(navigator.appVersion)<4) return; var strFound; if (window.find) { // CODE FOR BROWSERS THAT SUPPORT window.find strFound=self.find(str); if (!strFound) { strFound=self.find(str,0,1); while (self.find(str,0,1)) continue; } } else if (navigator.appName.indexOf("Microsoft")!=-1) { // EXPLORER-SPECIFIC CODE if (TRange!=null) { TRange.collapse(false); strFound=TRange.findText(str); if (strFound) TRange.select(); } if (TRange==null || strFound==0) { TRange=self.document.getElementById("area").createTextRange(); strFound=TRange.findText(str); if (strFound) TRange.select(); } } else if (navigator.appName=="Opera") { alert ("Opera browsers not supported, sorry...") return; } if (!strFound) alert ("String '"+str+"' not found!") return; } //--> I have around 100,000 html files that I need to do a search/replace on. I currently have the word "Manchester" in all of these files which needs replacing with the full file path location; C:\Demo_Folder\Manchester_file_001.html C:\Demo_Folder\Manchester_file_002.html Your help would really help me sort out my mind blowing task I've been given. Thanx in advance SuperZ Hi Guys, I have a javascript, which counts the specified words.. I want javascript to count some of the html tags and symbols when i enter a html code in the textarea.. - the below searchwords are not functioning properly. http://(space) http:/(space) etc... (no spaces are searching) - www. (.(dot) is not searching, also when i enter wwww(4 times) in the textarea it shows www. as count 1) - i can't enter the below symbols in searchwords array [ < ' ? I thank once again Bullant for helping me on the below script... But i am trying to fix my above issue and i couldn't.. :( Please help me out guys... Here is my Code... Code: <html> <head> <title>Word Count</title> <script type = "text/javascript"> function searchForWords(){ document.getElementById('resultsContainer').innerHTML = ''; var txt = document.getElementById('txtMsg').value; var strWords = document.getElementById('txtSearchWords').value; var searchWordsTokens = strWords.split(' '); var searchWords = ['href','LINK_ID','mailto','src="','src= ','src =','.jpg','.gif','.png','www','www.','http','http:// ','http:/ ','http: ','http ',' http',' "','@','amp;','TBD']; for(i=0; i < searchWordsTokens.length; i++){ if(searchWordsTokens[i].length > 0){searchWords.push(searchWordsTokens[i]);} //remove spaces between words } var results = [],matches; for(i=0; i < searchWords.length; i++){ var regex = new RegExp('\\b'+searchWords[i]+'\\b','gi'); matches = txt.match(regex); results[searchWords[i]] = (matches)? matches.length : 0; } //output results var str = ''; for(var i in results){ str += i+'--'+results[i]+'<br />'; } document.getElementById('resultsContainer').innerHTML = str; } window.onload=function(){ document.getElementById('form_submit').onclick=searchForWords; } </script> </head> <body> <table> <tr><td align="center"> <form id="contact_form"><h4>Paste your HTML Code he </h4> <p><label class="form_label" for='message'></label> <textarea rows="20" cols="60" id="txtMsg"></textarea> </p> <div> <input type="text" id="txtSearchWords"/> </div> <p><input id='form_submit' type="button" value="Check for Counts"></p> <div><p><input id='form_submit' type="reset" value="Clear"></p></div> <div id="resultsContainer"></div> </form><br /></td> </table> </body> </html> Hi all i have a question... In my below code, I need to get rid of the radio option in my file. Count pure words and Count everything as words Also if i specify some content in the input box, it shows all the word count in the output box. I need only few mentioned words to be dispalyed instead For example, if i give input as below in the input box "Java allows you to play online games, chat with people around the world, calculate your mortgage interest, and in view images in 3D, just to name a few. It's also integral to the intranet applications and and other e-business solutions that are the foundation of corporate computing." I need only to display the count of Java , yours , in , and so that i output will be Java - 1 yours - 0 in - 2 and - 3 Can someone help me out in this please... Thanks a lot!!!:) Html Code ======================================================= Code: <html> <head> <title> Word Count </title> <script language = "JavaScript"> function process1 (count) { // for words m=new Array(10000); m1=new Array(10000); N=new Array (10000); for (i=0;i<=1;i++) // which is chosen { if (count=1) { ch=i; } } A=count.message.value; // original message B=""; A=" " + A+" "; A=A.toUpperCase(); // changes all alphas to Upper case if (ch==0) // get rid of everything but apha's { condense1(count); } else { lesscondense(count); } for (i=1;i<=A.length;i++) // trims leading spaces and multiple spaces { if ((!(A.charAt(i)==" ")) || (!(A.charAt(i-1)==" "))) {B=B + A.charAt(i); } } //count.result1.value=B; B=B+" "; // makes sure there is a space at end k=0; str=" "; for (i=0;i<=B.length;i++) { k1=B.indexOf(str,k); if (k1==-1) //end of string B { Numwords=i-1; break; } m[i+1]=B.substring(k,k1); // places all the words into an array m k=k1+1; } //count.result1.value=B; C=""; NN=0; for (i=1;i<=Numwords; i++) // Numwords is total number of words { if (!(m[i]=="")) // only looks at m1 words that have not been processed before (not empty) { NN=NN+1; //unique word stored in m1 array m1[NN]=m[i]; N[NN]=1; // initialize counter for word for (j=i+1;j<=Numwords+1;j++) //counts and makes m1 elements with unique word empty. { if (m1[NN]==m[j]) { N[NN]=N[NN]+1; m[j]=""; } } } } C=C+"Unique:" + NN+" Total:" + Numwords+"\n"; C=C+"Freq.\tWord\n"; for (i=1;i<=NN;i++) // sets up C for showing { C=C + N[i]+ "\t" + m1[i] + "\n"; } count.result1.value=C; } function condense1(count) { // allows only alpha's and spaces for choice 1 C=""; for (i=0;i<=A.length-1;i++) { k=A.charCodeAt(i); if (((k>64) && (k<91)) || (k==32)) { C=C+A.charAt(i); } else { C=C+" "; } } A=C; //count.result1.value=B; } function lesscondense(count) { // allows all characters from space on C=""; for (i=0;i<=A.length-1;i++) { k=A.charCodeAt(i); if (k>31) { C=C+A.charAt(i); } else { C=C+" "; } } A=C; } //======================================== function letters1(count) { // counting characters upto unicode #255 mN=new Array(5000); for (i=0;i<=1;i++) // which is chosen { if ( count.radio2[i].checked) { ch1=i; } } A=count.message.value; T=0; for (i=0;i<=5000;i++) // initialize Array mN to 0 { mN[i]=0; } for (i=0;i<=A.length-1;i++) // k is character and counted in mN[k] { k=A.charCodeAt(i); mN[k]=mN[k]+1; } //count.result1.value=E; D=""; D=D+"Freq.\tLetter\n" if (ch1==0) // shows only alpha's and total number of letters T { for (i=65; i<91;i++) { if (!(mN[i]==0)) { D=D + mN[i] + "\t"+ String.fromCharCode(i) + "\n"; T=T+mN[i]; } } for (i=97;i<=122;i++) { if (!(mN[i]==0)) { D=D+mN[i]+"\t"+String.fromCharCode(i)+"\n"; T=T+mN[i]; } } } else // shows all characters from space (32) to unicode 255 { for (i=32; i<=255;i++) { if (!(mN[i]==0)) { D=D + mN[i] + "\t"+ String.fromCharCode(i) + "\n"; T=T+mN[i]; } } } count.result1.value=D; count.total.value=T; count.wordav.value=Math.round(T/Numwords*10000)/10000; // rounds off } //-- End </script> </head> <body> <form name ="count"><a name="Word_Counter"></a><font size="+1"><p> Count pure words<input type="radio" name="radio1" value="1" CHECKED> Count everything as words <input type ="radio" name="radio1" value="0"><br> <br> <table border="0" cellPadding="1" cellSpacing="1"> <tr> <td><input id="button1" name="button1" onclick="process1(document.count)" style="height: 24px; width: 165px; font-weight: bold" type="button" value="COUNT WORDS"></td> <strong><font face="Arial" color="#000080">Input your text into the box below:</font></strong><br><textarea cols=33 name=message rows=12 style="background-color: #ffffff; font-size: 10pt" wrap=PHYSICAL></textarea> <textarea cols=33 name=result1 rows=12 style="font-size: 10pt; font-family: Arial" wrap=PHYSICAL>WORD COUNT OUTPUT BOX</textarea> <br><table border=0 cellPadding=1 cellSpacing=1> <input type="reset" value="Reset" name="B1"> </body> </html> ======================================================= Hi, is it possible to create a script which exports data from a SQL server into MS Word? Sorry about the title, I didn't know what else to use to describe my problem. Basically, I'm generating a random word with a function; then I'm trying to pass this word down to another function. The problem is, when I pass the word, it changes each time (due to it being randomly generated originally). I'm only calling the function once (via button click), but I'm also calling the function in my code lower down to retrieve the returned variable; and the function seems to be running again and returning a new word from my array. Here's a snippet of my code: Code: function ranNum(){ var ranNum = Math.round(Math.random()*10); var chosenWord = wordArray[ranNum]; return chosenWord; } function makeBoxes(x){ //remove children when new word is chosen var hM = document.getElementById("hangMan"); while(hM.firstChild){ hM.removeChild(hM.firstChild); } var chosenWord = ranNum(x); var wL = chosenWord.length; //create box for length of letters in word var i = 0; for(i=0;i<wL;i++){ var cBoxes = document.createElement("div"); cBoxes.className = "letterBoxes"; cBoxes.innerHTML = chosenWord.charAt(i); hangMan.appendChild(cBoxes); } return chosenWord; } function checkLetter(y){ var chosenWord = makeBoxes(y); alert(chosenWord); } So I generate a word with one button; now I need to be able to work with said word in my checkLetter() function. The word changes however. Any help would be greatly received. I found a nice script online that will count words. Problem is, I need it to also count each DIGIT (0-9) as a seperate word, whether the numbers are seperated by a space or not. I've searched this forum to no avail. Can anyone help me or show me how to do this, here is the original script: Code: <!-- TWO STEPS TO INSTALL WORD COUNT: 1. Copy the coding into the HEAD of your HTML document 2. Add the last code into the BODY of your HTML document --> <!-- STEP ONE: Paste this code into the HEAD of your HTML document --> <HEAD> <SCRIPT LANGUAGE="JavaScript"> <!-- Original: Shawn Seley --> <!-- This script and many more are available free online at --> <!-- The JavaScript Source!! http://javascript.internet.com --> <!-- Begin function CountWords (this_field, show_word_count, show_char_count) { if (show_word_count == null) { show_word_count = true; } if (show_char_count == null) { show_char_count = false; } var char_count = this_field.value.length; var fullStr = this_field.value + " "; var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi; var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, ""); var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi; var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " "); var splitString = cleanedStr.split(" "); var word_count = splitString.length -1; if (fullStr.length <2) { word_count = 0; } if (word_count == 1) { wordOrWords = " word"; } else { wordOrWords = " words"; } if (char_count == 1) { charOrChars = " character"; } else { charOrChars = " characters"; } if (show_word_count & show_char_count) { alert ("Word Count:\n" + " " + word_count + wordOrWords + "\n" + " " + char_count + charOrChars); } else { if (show_word_count) { alert ("Word Count: " + word_count + wordOrWords); } else { if (show_char_count) { alert ("Character Count: " + char_count + charOrChars); } } } return word_count; } // End --> </script> </HEAD> <!-- STEP TWO: Copy this code into the BODY of your HTML document --> <BODY> <form> <textarea cols=40 rows=5 name=x> </textarea> <br> <input type=button value="Count Words" OnClick ="CountWords(this.form.x, true, true);"> </form> <p><center> <font face="arial, helvetica" size"-2">Free JavaScripts provided<br> by <a href="http://javascriptsource.com">The JavaScript Source</a></font> </center><p> <!-- Script Size: 2.04 KB --> Hey there CF members, i have a huge problem with dynamic JavaScript i am using .load function which is the part of my script built by my programmers to load objects dynamically in JS. the code reads PHP Code: $("#content").load("SOME CODE HERE",hideUpdate); The division id is Content as u can see above. the need is to add a html code at the beginning of it like in php we can use dot operator like "SOME CODE IS " . $ code same way what can we use in here in dynamic html to combine a custom HTML regards I have this piece of javascript code, which enables me to get my Picasa photos without link back feature, in my webpage. The issue is with the hardcoded RSS url feed. I want this to be dynamically passed as a variable to the java script. I use a PHP code, where this javascript is coded. In the below code, if I say var samples = <?php $url_code ?>, the javascript does not recognize. Can someone help on this, as I use the same PHP code, with different url feeds, to display different picasa photo albums ? Code: <script type="text/javascript"> function load() { var samples = "https://picasaweb.google.com/data/feed/base/user/......................../........./.........?alt=rss&kind=photo&authkey=.....................&hl=en_US" var options = { numresults: 2, scaleimages: true, maintainAspectRatio : false, displayTime: 1000, transistionTime: 300, //linkTarget : google.feeds.LINK_TARGET_BLANK }; new GFslideShow(samples, "slideshow", options); } google.load("feeds", "1"); google.setOnLoadCallback(load); </script> Hello, I've used the concept from this website to build a form. http://www.enviromark.ca/english/quoteform.html Notice how the second drop down options change depending on what option is selected in the first drop down. Here's the Javascript Code: var Option1_Array = new Array("Choose a version", "1", "2"); var Option2_Array = new Array("Choose a version", "3", "4"); function program(objProgram) { var objVersion = objProgram.form.Version; var selectedArray = window[objProgram.options[objProgram.selectedIndex].value.replace(/\s/g,'') + "_Array"]; objVersion.options.length = 0; for (var i=0; i < selectedArray.length; i++) { objVersion.options[i]=new Option(selectedArray[i], selectedArray[i].replace(/->\s/g, "")); } } Here's the HTML Code: <form> <select name="Program" onChange="program(this)"> <option value="Start">Please choose a program</option> <option value=Null>---------------------------------------></option> <option value="Option1">1</option> <option value="Option2">2</option> </select> <select name="Version" onChange=""> </select> </form> Now, this code works perfectly, and does exactly what I want it to. BUT I'd like to add more fields that accomplish the same thing. For example choose option1 --> version 2 --> type 3 --> thing 5 Now, in order to do this I believe you need to generate a 'value = "a_value"' in the generated html option and select fields. That way, all you need to do is make separate functions for each level and the function can call the 'value' html attribute to handle each <select> depending on its declared value. If this is the best way (it sounds a little sketchy to me) then any help would be great. Or, if you can add on more child selection options within one function. Thanks, -Matthew Hi, I'm trying to create a dynamic form using Javascript. This form essentially needs to collect data through certain fields and populate another. Code: <input name="Field1" type="text" /> <input name="Field2" type="text" /> <input name="Field3" type="text" /> <input name="Field4" type="text" /> <input name="Field5" type="text" /> Field 6 value = answer I'm stuck on how to go about this. I'm assuming I need to create multiple conditions to check each field and then output to a text box? Code: if ((document.thisform.Field1.value == null) && (document.thisform.Field2.value == null)) { I've done a bit of searching around but can't find anything with particular reference to this exact requirement, only brick level functions. If I have left anything out, or if it's all amiss, please let me know. Hello, I have been noticing a really cool trend on the web and it is called the javascript carousel. Not the one from dynamic Drive. Here is an example of what I am talking about; carousel http://food.yahoo.com/;_ylt=AtuShzEA...hz75HDg9VIY.Y5 check on the bottom of the page where it says "try these recipes" I just love the circle indicating how many "pages there are. Do you know where I can find the tutorial or script for this effect? Thanks, Creations_Kash Hi everyone, i am stuck at a problem. i am trying to craete a redimmensionable array using javascript, is there a way to do this, i know that this can be done in vbscript using redim and preserve commands. If not then is it possible to variables between javascript and vbscript, or call vbscript function using javascript. a sample code will be much aprreciated thanks for your time! J Hi, I'd like to create a textarea and a division so that whatever embed code you put in the textarea it gets executed on the division in real-time. Your kind help is greatly appreciated! JavaScript newbie hi friends, I am looking for a solution to display the records of a dynamically selected mysql table using ajax,jsp & js combinations. any sites showing some example thnx in advance. I have a signup form on a site that does a check on submission of fields to see if they populated and error box if not changes focus to missing field and highlights field name in red. I wanted to improve on its effectiveness as it only checks 2 fields atm and I wanted it to check some dynamic fields as well the fields are associative arrays generated via php as follows:- Code: echo "<select name='nfield[$t]'>\n"; for ($i = 0; $i<count($value2); $i++) { echo "<option value=\"".trim($value2[$i])."\">".trim($value2[$i])."</option>\n"; } echo "</select>"; the javascript is as follows:- Code: function checkForm() { //This is the name of the function if (Form1.password.value == "") { alert("Please enter a Password."); Form1.password.focus( ); document.getElementById('password').style.color="red"; return false; } The field is displayed via php as follows:- echo "<tr><td align='center' id='password'>Password:</td><td><input type='password' name='password' size='10'></td></tr>\n"; So i thought ah easy, i will just add the following checking javascript to check each of the associative arrays as they never change Code: if (Form1.nfield[1].value == "") { alert("Please choose an option for option1"); Form1.nfield["1"].focus( ); //This focuses the cursor on the problem field document.getElementById('nfield[1]').style.color="red"; return false; //This prevents the form from being submitted } if (Form1.nfield[2].value == "") { alert("Please choose an option for option2"); Form1.nfield[2].focus( ); //This focuses the cursor on the problem field document.getElementById('nfield[2]').style.color="red"; return false; //This prevents the form from being submitted } if (Form1.nfield[3].value == "") { alert("Please choose an option for option3"); Form1.nfield[3].focus( ); //This focuses the cursor on the problem field document.getElementById('nfield[3]').style.color="red"; return false; //This prevents the form from being submitted } but this doesn't work, i think it doesn't recognise the nfield[1] syntax, can a javascript guru point me in the right direction ? I also wanted to enhance the form somewhat as atm it only displays one error popup at a time, so if the user has missed out a few fields they will get an initial popup, try and submit again and then get the second popup for the other missing field. Can my code be modified to show a list of the missing fields and highlight all the titles in red (and if possible change the background colour of the input boxes or border the input fields in red etc)? not sure what section to post this in, basically i have html in a javascript function that i want to pass into a php. here is some of my javascript code Code: var names = document.getElementById('names').value; var nms = names.split(";;") for (i=0; i<las.length; i++) { var contentString = [ '<div id="tab-1">', '<p><h1>'+nms[i]+'</h1></p>', '</div>' +'<form action="index.php" method="post" enctype="multipart/form-data">'+ '<input id="delbutton" name="delbutton" type="submit" value="Delete">',+'</form>' } then when the button gets pressed it goes to Code: if(isset($_POST['delbutton'])=='Delete') { echo("into the php delete: " . $_POST['name2'] . "<br />\n"); echo '<pre>' . print_r($_POST,true) . '</pre>'; } basically i want to be able to access the value of nms[i] in the php call. i am able to pass anything in <input> tags like normal html, but i want to get nms[i] to go through what should i do? |