JavaScript - Simple Site Search
Is it possible to make a simple site search where if someone types in an exact keyword then they are taken directly to another page on the site. So the results page is skipped entirely? It's only for a personal site so I can skip directly to a page easily just by typing a keyword in a search box.
Hope you understand what I mean. And thanks. Similar TutorialsFirst off please forgive my ignorance, as I am very new to coding. I hope that I have posted this in the right place. I found a great piece of code that I would like to use for my site search. I found it he http://www.javascriptkit.com/script/...e_search.shtml Here is what I am attempting to do. I would like this piece of code to search all three of my domains, if this is possible. I would like to use this search box on all three of my websites, if this is possible. If you look at this site: www.kennedyassassinationresearch.com I would like to keep the look similar to what it is now, and use this code in the upper right corner of the header, where the black search box is now. Is any of this possible? the code I located is: Code: <form name="jksearch" action="http://www.google.com/search" method="get" onSubmit="jksitesearch(this)"> <p>Search JavaScript Kit:<br /> <input id="hiddenquery" type="hidden" name="q" /> <input name="qfront" type="text" style="width: 200px" value="navigator object" /> <input type="submit" value="Search" /><br /> <div style="font: bold 11px Verdana;">Google:<input name="se" type="radio" checked> *Yahoo:<input name="se" type="radio"> *MSN:<input name="se" type="radio"> </div> <script type="text/javascript"> // All-in-one Internal Site Search script- By JavaScriptKit.com (http://www.javascriptkit.com) // For this and over 400+ free scripts, visit JavaScript Kit- http://www.javascriptkit.com/ // This notice must stay intact for use //Enter domain of site to search. var domainroot="www.javascriptkit.com" var searchaction=[ //form action for the 3 search engines "http://www.google.com/search", "http://search.yahoo.com/search", "http://search.msn.com/results.aspx" ] var queryfieldname=["q","p","q"] //name of hidden query form for the 3 search engines function switchaction(cur, index){ cur.form.action=searchaction[index] document.getElementById("hiddenquery").name=queryfieldname[index] } function jksitesearch(curobj){ for (i=0; i< document.jksearch.se.length; i++){ //loop through radio to see which is checked if (document.jksearch.se[i].checked==true) switchaction(document.jksearch.se[i], i) } document.getElementById("hiddenquery").value="site:"+domainroot+" "+curobj.qfront.value } </script> </p> </form> <p style="font: normal 11px Arial">This free script provided by<br /> <a href="http://www.javascriptkit.com">JavaScript Kit</a></p> Any help is greatly appreciated, as this is a learning experience for me, and this has me quite confused. Thanks! I have a code for creating a search bar to search words on an unpublished site that i am developing. I was wondering where to enter the keywords, can anyone help me? Thanks; Code: <script language="JavaScript"> <!-- Original by http://javascript.internet.com More javascripts http://www.************** --> var NS4 = (document.layers); // Which browser? var IE4 = (document.all); var win = window; // window to search. var n = 0; function findInPage(str) { var txt, i, found; if (str == "") return false; // Find next occurence of the given string on the page, wrap around to the // start of the page if necessary. if (NS4) { // Look for match starting at the current point. If not found, rewind // back to the first match. if (!win.find(str)) while(win.find(str, false, true)) n++; else n++; // If not found in either direction, give message. if (n == 0) alert("Not found."); } if (IE4) { txt = win.document.body.createTextRange(); // Find the nth match from the top of the page. for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) { txt.moveStart("character", 1); txt.moveEnd("textedit"); } // If found, mark it and scroll it into view. if (found) { txt.moveStart("character", -1); txt.findText(str); txt.select(); txt.scrollIntoView(); n++; } // Otherwise, start over at the top of the page and find first match. else { if (n > 0) { n = 0; findInPage(str); } // Not found anywhere, give message. else alert("Not found."); } } return false; } </script> <form name="search" onSubmit="return findInPage(this.string.value);"> <div align="center" font size=3> <input name="string" type="text" size=15 onChange="n = 0;"> </font> <input type="submit" value="Search Page"> </div> </form> I'm trying to add an internal site search to my website, and it only work for some search items, not for everything. For example, if I search for Bud Light, Budweiser, Bud Light Lime, it finds them. But if I search for Stella Artois, Paulaner, or Hoegaarden, it doesn't find anything. I'm thinking there's something wrong with the javascript code, I'm just not sure how to fix it. I really appreciate any help with this!!! Here's the code in the head region: [<script type="text/javascript"> // Google Internal Site Search script- By JavaScriptKit.com (http://www.javascriptkit.com) // For this and over 400+ free scripts, visit JavaScript Kit- http://www.javascriptkit.com/ // This notice must stay intact for use //Enter domain of site to search. var domainroot="www.mhdbud.com" function Gsitesearch(curobj){ curobj.q.value="www.mhdbud.com:"+domainroot+" "+curobj.qfront.value } </script>] Here's what I've got in the body: [<form action="http://www.google.com/search" method="get" onSubmit="Gsitesearch(this)"> <input name="q" type="hidden" /> <input name="qfront" type="text" style="width: 180px" /> <input type="submit" value="Search" /> </form> You can try the site search to see what I'm talking about on this webpage: http://www.mhdbud.com/productsalt.html] I used the Google Internal Site Search script for my site but its search only the index.htm, how can I make it search the entir web site.
Hi all- I currently use a javascript seacrh string on my website that searchs all folders (directories) and gives results on a html page. My problem is that some folders (or sub directories) are not being found when I type into the form search box. Does anyone know why this might be happening? here is the script im using <script language="JavaScript" type="text/javascript">function OnSearchSubmit(){var b_return=true;if (document.form_search.sw){for(var i=0;i<document.form_search.sw.value.length;i++){if (document.form_search.sw.value.charAt(i)!=" ") {lh="searchresult.html?sw="+encodeURIComponent(document.form_search.sw.value);b_return=false;break;} }}if (b_return) return;window.open(lh,"_self");}</script> thanks! Hi all.... newbie here. Have just finished my eccomerce site and it's ready to go but have come across a stumbling block. I use webplus4 which is a great web design program... except for one thing. The site search tool is very weak... it won't find results for words of less than 4 characters... and since my website is about plush pets this is important. For instance if you type in the breed 'pug' it says 0 results found. Same if you enter Old English Sheepdog, it ignores the entire search term because of the world 'old'. If you enter plush pug, it also ignores the entire search string. I don't have the money to purchase software nor the time and then configure the javascript to match my site. Is there anyone out there that can modify the following javascript file (jsSiteSearch.js) so that the search will not ignore words of 3 letters? Am aware that once modified I will have to replace the file each time but it will be worth it. By the way, no one on the webplus forums seems to know how to do it. Here is the code... (have removed all the keywords)... function GetSiteSearchResults(newWindow,frameObject,frameObjectName,fontFace,fontSize,fontColour,linkFace,lin kSize,linkColour,resultsText) { var sTerms=""; var iDepth = 0; var sURL = new String(document.location); if (sURL.indexOf("?") > 0) { var arrParams = sURL.split("?"); var arrURLParams = arrParams[1].split("&"); for (var i=0;i<arrURLParams.length;i++) { var sParam = arrURLParams[i].split("="); var sValue = unescape(sParam[1]); if( sParam[0] == frameObjectName) sTerms = sValue; if( sParam[0] == "depth") iDepth = parseInt(sValue); } } var d=frameObject.document; if (sTerms=="") {d.open(); d.write("<html><head></head><body style=\"background: transparent;\"></body></html>"); d.close();return;} var sBack=""; for (i=0; i<iDepth; i++) sBack+='..\\\\'; d.open(); d.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); d.write("<html lang=\"en\">"); d.write("<head>"); d.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">"); d.write("</head>"); d.write("<body style=\"margin: 0px 0px 0px 0px; font-family: "+fontFace+"; font-size: "+fontSize+"; color: "+fontColour+"; background: transparent;\">"); d.write("<div id=\"wpSearchResults\"></div>"); d.write("<script type=\"text/javascript\">"); d.write("var wordMap = new Array(\"...........................................); d.write("function doNav(ind)"); d.write("{"); if (newWindow) d.write(" window.open(\""+sBack+"\"+linkMap[ind],\"_blank\");"); else d.write(" parent.window.location.href=linkMap[ind];"); d.write("}"); d.write("function wpDoSearch(searchTerms){"); d.write("var terms = searchTerms.split(\" \");"); d.write("if (terms==\"\") return;"); d.write("var results = \"\";"); d.write("var resultscount = 0;"); d.write("for (var i=0; i<wordMap.length; i++)"); d.write("{"); d.write(" var found=true;"); d.write(" for (var j=0; j<terms.length; j++)"); d.write(" if (wordMap[i].indexOf(terms[j].toLowerCase())==-1) found=false;"); d.write(" if (found)"); d.write(" {"); d.write(" results+=\"<a style=\\\"cursor: pointer; font-family: "+linkFace+"; font-size: "+linkSize+"; color: "+linkColour+"; \\\" onclick=\\\"doNav(\"+i+\");\\\"><u>\"+pageMap[i]+\"</u></a><br>\"+preMap[i]+\"...<br><br>\";"); d.write(" resultscount++;"); d.write(" }"); d.write("}"); d.write("document.getElementById(\"wpSearchResults\").innerHTML=resultscount+\" "+resultsText+" \"+searchTerms+\"<br><br>\"+results;"); d.write("}"); while(sTerms.indexOf("\"") != -1 ) { sTerms = sTerms.replace("\"",""); }; d.write("wpDoSearch(\""+sTerms+"\");"); d.write("</script>"); d.write("</body></html>"); d.close(); } Thanks so very much in advance. Any help asap will be much appreciated. Cheers Hi there, I've been scouring the web and my mind for the last 24 hours trying to find a script that will work for what I need. It seems like it would be something super simple. I need visitors to my site to be able to search if we offer service in their area. i.e. Enter Zip Code: [Search Field] (Submit Button) Pop-up results or a results page with one of two responses. Yes, we offer service. No, we do not cover your area. Something similar to what this company has on their site, http://www.oilpatchfuel.com/Pages/Welcome.aspx Any help is a greatly GREATLY appreciated!! Okay i started a cople of days dont have experience in coding on JavaScript I need to make search button like this ) but i doesn't work. The idea is i add words or something to an array and after i enter the word or something press search and it gives the position in array. Code: var m = new Array(); function add() { var q = document.getElementById('mEntry'); var temp = q.value ; m.push(temp); } function test() { } function search() { var d = document.getEntryById('searchEntry'); var compare = d.value; var i=0; for (i=0;i<=m.lenght;i++) { if( m[i] = compare) document.write(i); } } ------------- This works just fine ) Code: var m = new Array(); function add() { var q = document.getElementById('mEntry'); var temp = q.value ; m.push(temp); } function test() { } function search() { var sEntry = document.getElementById('searchEntry'); var key = sEntry.value ; for(i in m) { if(m[i] = key) {var answer = i;} } document.write(answer); } Can anyone get me a simple script for a search engine for my website? i cant find a decent 1 anywhere. thanks
In this case, Let's take Google Search as example: The code is JScript .NET, which is basically a .NET version of Javascript. Regardless of language, Anyone with appending type of skill can answer my question. This code is used in Fiddler(It's a Man-in-the-middle proxy) Code: if (oSession.uriContains("&q=")) // oSession is a Fiddler object session // uriContains() function, checks for case-insensitive string from the URI { var str = oSession.fullUrl; var sAppend = "test1+test2+test3"; if (!oSession.uriContains(sAppend)) { oSession.fullUrl = str.replace( "&q=","&q="+sAppend); } } For those who are confused, It says, If &q= is present in the URI, replace/append &q= with &q=test1+test2+test3 Problem: It appends test1+test2+test3 instantly, when it sees &q= in the URL. Basically, how do I make it wait until I click the submit/search button Thank you. Update: I heard about Onsubmit() event, but not really familiar with it. How do I use it? like, should I go to google source page and edit the form id? Also, Any other methods besides Onsubmit()? Hi Everyone! I have a website that I'm designing where I have the need to search multiple sites at specific times. By this I mean that In some cases, we would want to search only the internet using google, or only search the site that I've created (which currently uses the jse_search.js solution), or only our company's website. I currently have four different search boxes that will search either the internet, the internal site, a separate internal site, or a third-party website, which all working fine. The problem is that the search boxes take up quite a bit of space, and the layout is becoming cumbersome. Is there a way in Javascript I could use a single search box and a drop-down list to select which method to use? The code I'm currently using is below. With the exception of the Google search function, I've modified some of the site names to general site names and paths to preserve the company's anonymity: Code in the <head> tag: Code: <script language="JavaScript1.3" type="text/javascript" src="jse_form.js"> </script> Code in the <body> tag: Code: <!--Begin Internal Site Search 1!--> <div> <p style="text-align: center;"> <table border="0" cellpadding="0"> <tr><td><form name="jse_Form" onsubmit="search_form(jse_Form);return false"> <input type="text" name="d" size="30"> </tr></td> <tr><td> <input type="button" value="Internal Site Search 1" onclick="search_form(jse_Form)"> </form> </tr></td> </table> <!--End Internal Site Search 1!--> <!--Begin Internal Site Search 2!--> <div> <p style="text-align: center;"> <table border="0" cellpadding="0"> <tr><td> <!--webbot bot="Search" S-Index="all" S-Fields S-Text="Search for:" I-Size="20" S-Submit="Start Search" S-Clear="Reset" S-TimestampFormat="%m/%d/%Y" TAG="BODY" b-useindexserver="1" startspan --> <form action="http://sitesearch2.idq" method="POST"><input type="text" name="UserRestriction" size="30" value> </tr></td> <tr><td style="text-align: center;"> <input type="submit" value="Internal Site Search 2"></form> </form> <!--webbot bot="Search" i-checksum="4210" endspan --> </td></tr> </table> </div> <!--End Internal Site Search!--> <!--Begin Google Search!--> <form method="get" action="http://www.google.com/search"> <div> <p style="text-align: center;"> <table border="0" cellpadding="0"> <tr><td> <input type="text" name="q" size="30" maxlength="233" value="" /> </tr></td> <tr><td align="center"> <input type="submit" value="Google Search" /></td></tr> </table> </div> </form> <!--End Google Search!--> <!--Begin Third Party Search!--> <form id="keywordSearchForm" method="get" action="http://www.site3.html"> <div> <p style="text-align: center;"> <table border="0" cellpadding="0"> <tr><td> <input class="input" type="text" name="keyword" size="30" /> </tr></td> <tr><td align="center"> <input type="hidden" name="origin" value="keywordsearch" /><input id="go" class="button" tabindex="0" type="submit" value="Third Party Search" /> </td></tr> </table> </div> </form> <!--End Third Party Site Search!--> Hi experts, is it possible via Javascript to search certain websites with certain keywords without having to use specific search engines? example search only the following: 1. www.yyy.com 2. www.aaa.com 3. www.zzz.com for the keyword "Laminat" and open the sites accordingly. thx I'l not good in Javascript and I can't find anything about what I want.. . On a sports website there is a table with our ranking and results. On this site the content is changed weekly, but it stays in the same tables.. . Is it possible to make a javascript to get those tables and put them on my own website so the content will change on my site when the content is changed on the sports site? Please help me, it would save me lot of time.. . THx Hello people. I'm looking to create a simple search engine capable of searching multiple search engines simultaneously together (e.g. Google, Bing, Yahoo, etc.) and then displaying the results below for all sites on the same page. I don't want each search engine results page opening up in individual windows or anything, nor do I want people to have to manually select the search engine to search with. Just a single page where a user types in something, pressed [Enter] and then presented with all results from multiple sites on one page (without duplicates). I'm also looking to do this with image and torrent sites, etc. How would I go about doing this? Thanks a million guys. You have bigger brains than me. I imagine this would be very simple for someone who knows javascript. I want to have three fields. First field is "posted speed limit", second field is "actual speed" and third field will be the output field. All the script needs to do it subtract the posted speed from the actual speed and add a ZERO to the end; which is the amount of the speeding ticket. The minimum fine is $100, however. So, 5 miles over the speed limit would be $100 (minimum value) 15 miles over the speed limit would be $150 (add a zero) 35 miles over the speed limit would be $350. etc. I know very little Javascript, if anyone could help me out with this, I'd appreciate it. Thanks, Sean I have my own multi option search bar html Code: <form name="searchform" action="http://www.google.com/search?q=" onsubmit="return dosearch();"> Search: <select name="sengines"> <option value="http://www.google.com/search?q=">Google</option> <option value="http://search.yahoo.com/search?q=">Yahoo</option> <option value="http://www.bing.com/search?q=">Bing</option> <option value="http://www.playlist.com/searchbeta/tracks#">Playlist</option> <option value="http://www.youtube.com/results?search_query=">Youtube</option> <option value="http://www.hulu.com/search?query=">Hulu</option> <option value="http://www.tv.com/search.php?type=11&stype=all&tag=search%3Bfrontdoor&qs=">TV.com</option> <option value="http://www.ask.com/web?q=">Ask</option> <option value="http://www.answers.com/topic/">Answers</option> <option value="http://www.ehow.com/search.aspx?s=">eHow</option> <option value="http://en.wikipedia.org/wiki/">Wikipedia</option> <option value="http://search.forbes.com/search/find?tab=searchtabgeneraldark&MT=">Forbes</option> </select> For: <input type="text" name="searchterms" /> <input class="button" type="submit" name="SearchSubmit" value="Search" /> </form> javascript (external) Code: function dosearch() { var sf=document.searchform; var submitto = sf.sengines.options[sf.sengines.selectedIndex].value + escape(sf.searchterms.value); window.location.href = submitto; return false; } but I want to have a second drop-down menu. I just can't get the 2nd one have everything still work. Can some benevolent sheep-guider-person (whatever they're called) help me? Thanks in advance, man with unnecessary phallic staff. Good Day: I am building a small website that lists the local restaurants in the area. I would like to have a search bar at the top of the page so the user could type in the name of the restaurant and it takes you to my review. The way I have it set now, is the user has to scroll down to find the restaurant. The saerch bar would be much easier. Thanks in advance for any and all assistance. I am using javascript to search for the '*' character in a string (ie. 'username*:') but using search('\*') does not work. How do I search for it since the search function takes a regexp argument and * messes that up?
I'm not sure if this is the right forum, but I'm looking for help with adding a search box to my website. I want to create a keyword search box - one where entering the right keyword(s) will take the visitor DIRECTLY to the page they're looking for, without a results page. And if they don't enter a keyword (in a keyword database?) they're taken to an error page. So, in essence, it's not really a search engine, it's more of a keywords box. Oh, also, some of the keywords will have non alphabetical or numerical characters (like dashes and periods) if that's a concern. Can someone help me with this or point me in the right direction to someone/someplace that can? Thanks.
Hello, I have a search textbox field which populates the results in a dropdown after searched. But there is no way, to let users to explain to click or use the dropdown to see the results.. thus, I would like to have a focus on the dropdown, so after the user searches through the search textfield, and enter, the dropdown gets the focus so it will user friendly. can anyone help me on this. thank you in advance |