www.webdeveloper.com
Results 1 to 11 of 11

Thread: Javascript code - Search button

  1. #1
    Join Date
    Dec 2008
    Posts
    93

    Javascript code - Search button

    Hi everybody,

    I am a new member in this forum and new to Javascript.

    I am building a web site and want to write Javascript code for SEARCH button.

    Can somebody help me with this?


    Thanks in advance

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    You will have to describe in more detail if you want someone to help you.
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Dec 2008
    Posts
    93
    Hi Fang

    In details... yes... I want to create a SEARCH BUTTON in header area of my web site. I put my slice in Dreamweaver (from Photoshop) and now my search button only can been seen and has no function at all. I want to write the code for this button in order to make it work.

    How can I do that?

  4. #4
    Join Date
    Nov 2008
    Posts
    82
    you must create a event of this button like <input type='button' onlick="javascript:alert('ldfldlfd');"> , then find the button can work.

  5. #5
    Join Date
    Dec 2008
    Posts
    93
    Thanks for your reply!

    What about javascript code???

  6. #6
    Join Date
    May 2008
    Posts
    21
    Uh... do you want to make a search engine for your site? If so, you can't really do it with Javascript. You can get a Google search engine for your site here:
    http://www.google.com/webmasters/tour/tour1.html

  7. #7
    Join Date
    Dec 2008
    Posts
    93
    Yeah. I would like to make a search engine only for my site (not Google SE). If not with Javascript, how can I do that?

    Thanks.

  8. #8
    Join Date
    May 2010
    Posts
    3
    I have exactly the same question. searching for couple of weeks now. can't find an answer anywhere. my host does not support SQL database the uploading and running of server side code. advice form them utilize Javascript into my pages and posts.
    please help.

  9. #9
    Join Date
    May 2010
    Posts
    3
    well, i just found something, not sure if that one will help
    http://www.webreference.com/programm...ion/index.html

    Arjeta, but if you will find the code, can you please let me know
    thanks

  10. #10
    Join Date
    May 2010
    Posts
    3
    i found very useful information, how how to insert javascript code into your website. just change name and it is done.
    http://www.javascript.freeuk.com/create.html

    <HTML>
    <HEAD>
    <SCRIPT language=JavaScript>
    <!--
    page=new Array()

    //
    // JavaScript Search Engine.
    // See www.javascript.freeuk.com for details.
    //
    // Enter your page indexes here.
    // Each page must be on one line only and be numbered consecutively starting from 1.
    //

    page[1]=["http://www.yourserver.com/stuff.html","Page title","Page description","Page body text"]

    //
    // You can alter the way the Javascript Search Engine works by changing the values below.
    // Change these if you do not like the default behaviour. Only use true or false.
    //

    // Do you want detailed output quoting each occurence of the search word?

    var ShowDetailedOutput = true

    // Do you wish to show the number of times the word is quoted?

    var ShowQuoteCount = true

    // Do you want the matched pages listed in order of relevance?

    var SortResults = true

    // Do you change the sort ordering? You can do this by altering the following numbers.
    // For example, if you want URL matches above Description matches then change
    // SortOrderDescription = 3 and SortOrderURL = 2

    var SortOrderTitle = 1
    var SortOrderDescription = 2
    var SortOrderURL = 3
    var SortOrderContent = 4

    ///////////////////////////////////////////////////////////////////////
    //
    // Do not alter any script code below this line.
    //
    ///////////////////////////////////////////////////////////////////////

    var jsse01 = 0;var jsse02 = 1;var jsse03 = 2;var jsse04 = 3;var jsse05 = 4;var jsse06 = 5;var jsse07 = 6;var jsse08 = 7;var jsse09 = 8;var jsse10 = "";var jsse21;
    function InitialFocus(){ document.formSearch.txtSearch.focus(); }
    function jsse71(jsse11) { if ((jsse11>="a" && jsse11<="z") || (jsse11>="A" && jsse11<="Z") || (jsse11>="0" && jsse11 <="9")) { return true; } else{ return false; } }
    function jsse75( jsse14, jsse22, jsse12 ) { var jsse25 = page[jsse14][jsse22].toUpperCase(); var jsse13, jsse23, jsse24; var jsse45 = 0; page[jsse14][jsse06]=0; jsse13=jsse25.indexOf( jsse12 ); while( jsse13 >= 0 ) { jsse45 = jsse45 + jsse13 + 1;if (jsse13 == 0) {jsse23=false;}else{jsse23=jsse71(jsse25.charAt(jsse13-1));}if ( jsse25.length - jsse13 == jsse12.length){jsse24 = false;}else{jsse24 = jsse71(jsse25.charAt(jsse13 + jsse12.length));}if (!jsse23 && !jsse24){page[jsse14][jsse09+page[jsse14][jsse06]] = jsse45 - 1;page[jsse14][jsse06] ++;}jsse25 = jsse25.substring(jsse13+1,jsse25.length);while( jsse71(jsse25.charAt(0)) && jsse25.length > 0 ){jsse25 = jsse25.substring( 1, jsse25.length ); jsse45 ++;}jsse13 = jsse25.indexOf(jsse12);}}
    function jsse92( jsse14, jsse12 ){ var jsse22=0, jsse44; page[jsse14][jsse05]=-1; do { jsse44 = jsse22==0 ? 1 : (jsse22==1 ? 0 : (jsse22==2 ? 2 : 3)); jsse75( jsse14, jsse44, jsse12 ); if ( page[jsse14][jsse06] > 0 ) { page[jsse14][jsse05] = jsse44; } } while( jsse22++ < jsse04 && page[jsse14][jsse05]==-1 );}
    function jsse98(){ var jsse14, jsse22, jsse38, jsse39;var jsse40 = 100000; for( jsse14=1; jsse14<page.length; jsse14++ ) { page[jsse14][jsse08] = jsse14; } if( SortResults ) { for( jsse14=1; jsse14<page.length; jsse14++ ) { if( page[jsse14][jsse05] == jsse02 ) { page[jsse14][jsse07] = (4-SortOrderTitle) * jsse40; } else if( page[jsse14][jsse05] == jsse03 ) { page[jsse14][jsse07] = (4-SortOrderDescription) * jsse40; } else if( page[jsse14][jsse05] == jsse01 ) { page[jsse14][jsse07] = (4-SortOrderURL) * jsse40; } else { page[jsse14][jsse07] = (4-SortOrderContent) * jsse40 + page[jsse14][jsse06]; } } for( jsse14=2; jsse14<page.length; jsse14++ ) { jsse38 = page[jsse14][jsse07]; jsse39 = page[jsse14][jsse08]; for( jsse22=jsse14; jsse22>1 && jsse38 > page[jsse22-1][jsse07]; jsse22--) { page[jsse22][jsse07] = page[jsse22-1][jsse07]; page[jsse22][jsse08] = page[jsse22-1][jsse08]; } page[jsse22][jsse07] = jsse38; page[jsse22][jsse08] = jsse39;}}}
    function jsse97( jsse14 ) { var jsse46 = page[jsse14][jsse06]==1 ? "" : "s"; jsse10 += "<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SMALL><font color=gray>(" + page[jsse14][jsse06] + " quote" + jsse46 + ")</font></SMALL>";}
    function jsse63( jsse14, jsse37 ){ var jsse33; var jsse34;var jsse35=false; var jsse36=page[jsse14][jsse09 + jsse37 - 1]; jsse33 = jsse36<30 ? jsse33=0 : jsse33=jsse36-30; jsse34 = (jsse36+30 > page[jsse14][jsse04].length) ? jsse34=page[jsse14][jsse04].length : jsse34=jsse36+30; while ((jsse33>=0) && !jsse35){ if(jsse71(page[jsse14][jsse04].charAt(jsse33))) { jsse33--; } else { jsse35=true; } } jsse33++; jsse35=false; while ((jsse34 > jsse36) && !jsse35) { if(jsse71(page[jsse14][jsse04].charAt(jsse34))) { jsse34--; } else { jsse35=true; } } jsse10 += "<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\".. "+page[jsse14][jsse04].substring(jsse33,jsse36); jsse10 += "<B>" + page[jsse14][jsse04].substring(jsse36 , jsse36 + jsse21.length ) +"</B>"; jsse10 += page[jsse14][jsse04].substring(jsse36 + jsse21.length ,jsse34) + " ..\"";}
    function jsse64( jsse14 ) { if( ShowDetailedOutput ) { for( var jsse22=1; jsse22<=page[jsse14][jsse06]; jsse22++ ) {jsse63( jsse14, jsse22 );}}else{jsse63( jsse14, 1 );}if( ShowQuoteCount ){jsse97( jsse14 );}}
    function jsse61( jsse25, jsse36 ) { jsse10 += jsse25.substring( 0, jsse36 ); jsse10 += "<B>" + jsse25.substring( jsse36 , jsse36 + jsse21.length ) +"</B>"; jsse10 += jsse25.substring( jsse36 + jsse21.length ,jsse25.length ); }
    function jsse83( jsse14, jsse31 ) { jsse10 += "<P><B>" + jsse31 +". "; jsse10 += "<A href=\""+page[jsse14][jsse01]+"\">"+page[jsse14][jsse02]+"</A></B><BR>"; jsse10 += "&nbsp;&nbsp;&nbsp;&nbsp;<SMALL>URL&nbsp;&nbsp;</SMALL><font color=gray>"; if( page[jsse14][jsse05]==jsse01 ) {jsse61( page[jsse14][jsse01], page[jsse14][jsse09] );}else{jsse10 += page[jsse14][jsse01];}jsse10 += "</font>";if( page[jsse14][jsse05]==jsse03 ){jsse10 += "<BR>&nbsp;&nbsp;&nbsp;&nbsp;";jsse61( page[jsse14][jsse03], page[jsse14][jsse09] );}else{if( page[jsse14][jsse03].length > 0 ){jsse10 += "<BR>&nbsp;&nbsp;&nbsp;&nbsp;" + page[jsse14][jsse03];}else{jsse10 += "&nbsp;&nbsp;&nbsp;&nbsp;";}}if ( page[jsse14][jsse05]==jsse04 ){jsse64(jsse14);}else{jsse10+="</P>";}}
    function jsse82() { var jsse31 = 0; for( var jsse14=1; jsse14<page.length; jsse14++ ) { if( page[page[jsse14][jsse08]][jsse06] > 0 ) { jsse83(page[jsse14][jsse08], ++jsse31); } }}
    function jsse89() { jsse10 += "<HTML><HEAD><TITLE>Search results for \"" + jsse21 + "\"</TITLE></HEAD>"; jsse10 += "<BODY>You searched for <B>" + jsse21 +".</b>";}
    function jsse86() { var jsse32=0;for( var jsse14=1; jsse14<page.length; jsse14++ ){if( page[jsse14][jsse06]>0 ){jsse32 ++;}}if(jsse32==0){jsse10 += "<P>No pages matched your search.&nbsp;&nbsp;";}else{var jsse46 = jsse32==1 ? "" : "s";jsse10 += "<P>" + jsse32 + " page" + jsse46 + " listed.&nbsp;&nbsp;";}jsse10 += "<A href=\"javascript:history.go(-1)\"><B>Search Again</B></A></P>";jsse10 += "<P><SMALL>Powered by <A HREF=\"http://www.javascript.freeuk.com\">JavaScript Search Engine</A> 1999</SMALL></P>";jsse10 += "</BODY></HTML>";}
    function jsse81(){ var jsse47 = jsse10; document.open(); document.write(jsse47); document.close();}
    function jsse77( jsse25 ){ var jsse48=""; for( var jsse14=0; jsse14<jsse25.length; jsse14++){if( jsse25.charAt(jsse14)=="<" ){jsse48 += "&lt;";}else if( jsse25.charAt(jsse14)==">" ){jsse48 += "&gt;";}else{jsse48 += jsse25.charAt(jsse14);}}return( jsse48 );}
    function ClickSearch(){ var jsse12; jsse21=document.formSearch.txtSearch.value;if ( jsse21.length > 0 ){jsse21 = jsse77(jsse21);jsse12 = jsse21.toUpperCase() ; for( var jsse14=1; jsse14<page.length; jsse14++ ){jsse92( jsse14, jsse12 );}jsse98();jsse89();jsse82();jsse86();jsse81();}}

    ///////////////////////////////////////////////////////////////////////
    //
    // End of JavaScript Search Engine script
    //
    ///////////////////////////////////////////////////////////////////////-->

    </SCRIPT>
    <TITLE>Search this site</TITLE>
    </HEAD>
    <BODY onLoad=InitialFocus()>
    <FORM name=formSearch action="javascript:ClickSearch() //">
    <INPUT name=txtSearch >&nbsp; <INPUT name=send type=submit value=Search>
    </FORM>
    <P>&nbsp;</P>
    </BODY>
    </HTML>

  11. #11
    Join Date
    Jun 2014
    Posts
    1

    here use this one , you can even create your search engine with it like Google

    <!-- TWO STEPS TO INSTALL SITE SEARCH:

    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: Dion (biab@iinet.net.au) -->
    <!-- Web Site: http://www.iinet.net.au/~biab -->

    <!-- This script and many more are available free online at -->
    <!-- The JavaScript Source!! http://www.javascriptsource.com -->

    <!-- Begin
    var item = new Array();

    /* Here is where all the magic happens.
    Just enter as many additional pages that
    that you want to search, then fill in the
    additional listings for each page.
    */

    // "Page Name","path","Page Title","Many,Key,Words","Descriptive Comments"

    c=0; item[c]=new Array("index.html","","DemoSite","index,main,start,home,front","Demonstration search engine data about an imagined but probable internet site.");
    c++; item[c]=new Array("about.htm","","About Me","about,author,contact,email,who","Contact details and general information about the creator of the site and what the site is about.");
    c++; item[c]=new Array("links.htm","","Links page","links,more,where,similar,friends","Links to my favourite sites which I find interesting. Other friends sites which have similar interests to my own.");
    c++; item[c]=new Array("main.htm","main/","Main Page","content,main,focus","The main part of my site which contains what you have come to see. Lots of stuff like that and more great things. All in a sub directory.");
    c++; item[c]=new Array("logo.jpg","main/images/","Link Logo","link,image,logo,graphic","The logo.jpg is just a small image which you can place on your site as a link to me. It's in a second level subdirectory.");

    page="<html><head><title>Search Results</title></head><body bgcolor='white'><center><table border=0 cellspacing=10 width=80%>";


    function search(frm) {
    win = window.open("","","scrollbars");
    win.document.write(page);
    txt = frm.srchval.value.split(" ");
    fnd = new Array(); total=0;
    for (i = 0; i < item.length; i++) {
    fnd[i] = 0; order = new Array(0, 4, 2, 3);
    for (j = 0; j < order.length; j++)
    for (k = 0; k < txt.length; k++)
    if (item[i][order[j]].toLowerCase().indexOf(txt[k]) > -1 && txt[k] != "")
    fnd[i] += (j+1);
    }
    for (i = 0; i < fnd.length; i++) {
    n = 0; w = -1;
    for (j = 0;j < fnd.length; j++)
    if (fnd[j] > n) { n = fnd[j]; w = j; };
    if (w > -1) total += show(w, win, n);
    fnd[w] = 0;
    }
    win.document.write("</table><br>Total found: "+total+"<br></body></html>");
    win.document.close();
    }
    function show(which,wind,num) {
    link = item[which][1] + item[which][0];
    line = "<tr><td><a href='"+link+"'>"+item[which][2]+"</a> Score: "+num+"<br>";
    line += item[which][4] + "<br>"+link+"</td></tr>";
    wind.document.write(line);
    return 1;
    }
    // End -->
    </script>
    </HEAD>

    <!-- STEP TWO: Copy this code into the BODY of your HTML document -->

    <BODY>

    <center>

    <form method=get action="javascript:void(0)" onsubmit="search(this); return false;">
    <tr><td><input type=text name=srchval value=""><input type=submit value="Search"></td></tr>
    </form>

    </center>

    <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: 3.16 KB -->

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles