Results 1 to 7 of 7
  1. #1

    Javascript/HTML Multi Search Question

    I have noooo idea if I am even posting this in the correct area, let alone the correct site. If not I apologize and maybe someone could direct me elsewhere.
    I am trying to add a custom search into my site.

    http://www.jeffknowsloans.com

    you can see it about the middle of the page.

    I am using the following script to do so.


    Code:
    <script type="text/javascript">
    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;
    }
    </script>
    <form name="searchform" onSubmit="return dosearch();">
    Select County
    <select name="sengines">
    <option value="http://www2.co.washington.mn.us/opip/mod/addresssrch/result.asp?housenum=&street=" selected>Washington</option>
    <option value="http://rrinfo.co.ramsey.mn.us/public/characteristic/PropertySearchResults.aspx?pin=&Nbr=&Street=&pg=1" selected>Ramsey</option>
    <option value="http://www.altavista.com/web/results?q=">Alta Vista</option>
    <option value="http://www.dogpile.com/info.dogpl/search/web/">Dogpile</option>
    </select>
    Street Address:
    <input type="text" name="searchterms">
    <input type="submit" name="SearchSubmit" value="Search">
    </form>
    here is the problem i am running into.
    I dont know how to ignore or add certain parts of the search when it sends. for example. take a look at
    Code:
    <option value="http://rrinfo.co.ramsey.mn.us/public/characteristic/PropertySearchResults.aspx?pin=&Nbr=&Street=&pg=1" selected>Ramsey</option>
    When i try to do a search under this drop down selection it doesnt work. because it needs the &pg=1 to be added to the users request.
    Meaning if I set it to
    Code:
    http://rrinfo.co.ramsey.mn.us/public/characteristic/PropertySearchResults.aspx?pin=&Nbr=&Street=
    they type in their street name and the street name inputs into the search query but it wont fully work because it doesnt add the &pg=1 after it all.
    how in the world do I get it to add things like that?

    another example

    taking a look at

    Code:
    <option value="http://www2.co.washington.mn.us/opip/mod/addresssrch/result.asp?housenum=&street=" selected>Washington</option>
    this search function should technically be

    Code:
    <option value="http://www2.co.washington.mn.us/opip/mod/addresssrch/result.asp?" selected>Washington</option>
    however since i dont know how to add certain functions to the search i have to skip the housenum option. that means my customers cant search by street number. I want them to be able to type in their house number and their street address and it will change to what each seperate (outside) search engine needs.

    Does this make any sense at all?


    ie. i basically need a way to have the form/script add certain strings (&whatever=) into the query and also be able to subtract them.

  2. #2
    Administrator Dave's Avatar
    Join Date
    Sep 2004
    Location
    Te Awamutu, New Zealand
    Posts
    3,959
    Blog Entries
    79
    First, the ramsey search - try this: Instead of adding &pg=1 to the end of the query string, include it earlier. It doesn't usually matter which order these parameters are listed in the URL as long as they're all there and the syntax is correct. So for example:

    Code:
    <option value="http://rrinfo.co.ramsey.mn.us/public/characteristic/PropertySearchResults.aspx?pin=&Nbr=&pg=1&Street=" selected>Ramsey</option>
    That gets the pg parameter in there while still leaving the search query (Street) at the end of the string.

    The washington.mn.us one is a little more involved. You'll need to add another parameter to the search string. The easiest and most robust approach would be to have another form field for the street number, rather than have both the number and name in the same field. So let's say you call that field streetnum, you could try this (add the "if" statement in the appropriate place):

    Code:
    var submitto = sf.sengines.options[sf.sengines.selectedIndex].value + escape(sf.searchterms.value);
    if (sf.streetnum.value.length > 0) {
       submitto += '&amp;housenum=' + escape(sf.streetnum.value);
    }
    window.location.href = submitto;
    I haven't tested this or even reviewed it thouroughly so I can't guarantee it will work, but give it a try and let me know how you get on.
    Dave Owen
    MediaCollege.com

  3. #3
    Yes, this forum is the right address..


    Stripping that "pg=1" inside the HTML, then, adding it back "conditionally" at the "doSearch()" we'll have the following:

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title>we love the *web* stabdards</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <style type="text/css">/*<![CDATA[*/ label { display:inline-block;width:180px;text-align:right;margin-right:1em;line-height:1.50em } /*]]>*/</style>
    <script type="text/javascript">
    <!--//
            /*<![CDATA[*/
    
        function dosearch() {
            var sf=document.searchform;
            var submitto = sf.sengines.options[sf.sengines.selectedIndex].value + escape(sf.searchterms.value) + ((sf.sengines.selectedIndex=='1')?('&pg=1'):(''));
            window.location.href = submitto;
            return false;
        }
    
        /*]]>*/
    //-->
    </script>
    
    </head>
    <body>
    
    <fieldset>
        <legend>custom search</legend>
        <form name="searchform" method="get" target="_blank" action="." onSubmit="return dosearch();">
            <label for="_sc">Select County:</label>
            <select name="sengines" id="_sc">
                <option value="http://www2.co.washington.mn.us/opip/mod/addresssrch/result.asp?street=" selected="selected">Washington</option>
                <option value="http://rrinfo.co.ramsey.mn.us/public/characteristic/PropertySearchResults.aspx?Street=">Ramsey</option>
                <option value="http://www.altavista.com/web/results?q=">Alta Vista</option>
                <option value="http://www.dogpile.com/info.dogpl/search/web/">Dogpile</option>
            </select>
            
            <br />
            
            <label for="_sa">The Street Address:</label>
            <input type="text" name="searchterms" id="_sa" />
            <input type="submit" name="SearchSubmit" value="Search" />
        </form>
    
    </body>
    </html>
    Substituting the corresponding lines will do the fix..

    best regards;
    - kunter ilalan web designer
    follow him on twitter and on MediaCollege

  4. #4
    the problem is each site im sending the query out to is slightly different. This is getting closer to what I am looking for. On a scale of 1-100 im about a 7 when it comes to this stuff. but i learn and understand quickly.

    Code:
    if (sf.sengines.options[sf.sengines.selectedIndex].value == "Ramsey") {
    	submitto = "http://rrinfo.co.ramsey.mn.us/public/characteristic/PropertySearchResults.aspx?pin=&Nbr=&Street=" + escape(sf.searchterms.value) + "&pg=1";
    can i actually set that up for each drop down box?
    because each sites query string is a little different.

    can i then add multiple "if" options? ie.

    Code:
    var submitto
    if (sf.sengines.options[sf.sengines.selectedIndex].value == "Ramsey") {
    	submitto = "http://rrinfo.co.ramsey.mn.us/public/characteristic/PropertySearchResults.aspx?pin=&Nbr=&Street=" + escape(sf.searchterms.value) + "&pg=1";
    if (sf.sengines.options[sf.sengines.selectedIndex].value == "Washington") {
           submitto = "http://www2.co.washington.mn.us/opip/mod/addresssrch/result.asp?housenum=" +
    escape(sf.searchterms.value) + "&street=";
    else
    	submitto = sf.sengines.options[sf.sengines.selectedIndex].value + escape(sf.searchterms.value);
    }
    window.location.href = submitto;
    return false;
    }
    basically. can i just add if statement after if statement after if statement?

    edit: I tried this and its not working. its not sending out the correct info. when i click submit I get

    http://www.jeffknowsloans.com/?sengi...hSubmit=Search

    instead of it sending out to the site.

  5. #5
    shoot. did i reply back to this already?

    if not

    i was told to use if commands. however it still isnt sending the info to the correct site.

    What I really need. Is two form fields.
    one for house number and one for street number

    but then I need each of those forms to send the information to each sepertate site in a different way.

    field one: 100
    field two: Street


    it needs to send that to one site as
    number=100&street=Street

    it needs to send it to another site as
    Nbr=100&Strt=Street

    I need it so depending on what drop down box they pick, it changes how it sends.

  6. #6
    please check this forum for more information.

    i really appreciate it guys. very close to getting this 2 week problem resolved.

    http://www.javaforums.net/forum/gene...0.html;new#new

  7. #7
    Although my previous example was perfectly fine and could be adjusted to your additional requests with little effort, but since you have decided "us" to do it so, well, here it is;

    - the working code:

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title>we love the web standards</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <style type="text/css">/*<![CDATA[*/ 
        fieldset {position:relative;width:500px;padding:20px;-moz-border-radius:10px;-webkit-border-radius:10px}
        legend {text-align:center;padding:3px 18px 3px 15px;border:1px solid silver;font:oblique 300 10px georgia;}
        input {padding:1px 3px;}
        label {display:inline-block;width:180px;text-align:right;margin-right:1em;line-height:2em;}
        option    {padding:0 30px;line-height:2em} select {padding-bottom:3px;vertical-align:middle}
        dl {display:inline-block;position:relative}
        dl dd {margin:0 .25em;display:inline-block}
        dd input,select {border:0px dotted silver;border-width:0 0 1px;font-size:1.1em;}
        dt {display:block;position:absolute;text-align:right;bottom:-1.33em}
        dt label {width:auto;font-size:9px;margin:0 5.67em 0 .67em}
        ul {display:block;width:100%;margin:1.50em .50em .50em;list-style:none}
        ul li input {float:left;margin:.25em;padding:0 1em}
        footer {display:block;position:absolute;right:45px;top:1px;width:67px;text-transform:uppercase;font:normal 300 7px/5px tahoma;text-align:center;letter-spacing:1px;padding:6px;-moz-border-radius:8px;-webkit-border-radius:8px}
        footer:first-line {font:normal 300 16px/16px helvetica}
        footer a, footer a:visited {text-decoration:none;color:#dedede} footer:hover {background-color:slategray} footer:hover a {color:#fff}/*]]>*/</style>
    <script type="text/javascript">
    <!--//
            /*<![CDATA[*/
    
        function dosearch() {
            var sf       = document.searchform;
            var _sCty    = sf.sengines.options[sf.sengines.selectedIndex].value;
            var _sNum    = escape(document.getElementById('sNum').value);
            var _sNam    = escape(document.getElementById('sNam').value);
            var sPattern = '';
    
            switch (sf.sengines.selectedIndex) {
                case 1:
                sPattern = 'http://www2.co.washington.mn.us/opip/mod/addresssrch/result.asp?street=' + _sNam + ((_sNum!='')?('&housenum=' + _sNum + '&stType=0&city=ALL'):(''));
                break;
    
                case 2:
                sPattern = 'http://rrinfo.co.ramsey.mn.us/public/characteristic/PropertySearchResults.aspx?Street=' + _sNam + ((_sNum!='')?('&Nbr=' + _sNum):('')) + '&pg=1';
                break;
    
                case 3:
                sPattern = 'http://www.altavista.com/web/results?q=' + '"property information" AND ' + '"' + ((_sNum!='')?(_sNum + ' '):('')) + _sNam + '"';
                break;
    
                case 4:
                sPattern = 'http://www.dogpile.com/info.dogpl/search/web/';
                break; // you have the examples, follow the same fashion..
            }
    
            window.location.href = sPattern;
            return false;
        }
    
        /*]]>*/
    //-->
    </script>
    
    </head>
    <body>
    
    <fieldset>
        <legend>custom search</legend>
    
        <form name="searchform" method="get" action="." onSubmit="return dosearch();">
    
            <label for="_sc">Select County:</label>
    
            <select name="sengines" id="_sc" title="choose search engine" required>
                <option selected></option>
                <option>Washington</option>
                <option value="http://rrinfo.co.ramsey.mn.us/public/characteristic/PropertySearchResults.aspx?Street=">Ramsey</option>
                <option value="http://www.altavista.com/web/results?q=">Alta Vista</option>
                <option value="http://www.dogpile.com/info.dogpl/search/web/">Dogpile</option>
            </select>    <br />
    
            <label>The Street Address:</label>
    
            <dl>
                <dt><label for="sNum">Str. No</label><label for="sNam">Street Name</label></dt>
                <dd><input type="text" id="sNum" title="street number [0-9]" pattern="[0-9]" size="3" /></dd>
                <dd>/</dd>
                <dd><input type="text" id="sNam" title="street name" size="10" required /></dd>
            </dl>
    
            <ul>
                <li><input type="reset" value="Clear" /></li>
                <li><input type="submit" name="SearchSubmit" value="Search" /></li>
            </ul>
    
        </form>
    
        <footer><a href="http://www.mediacollege.com/forum/showthread.php?t=6956" title="the copyright (c) information">media college.com</a></footer>
    
    </body>
    </html>

    I believe we had, now, "fully" solved your "situation".. the code can be improved, but this is obviously your part of the job. Trying "114 Churchill" you can see the results - except the last engine, that I had no idea what it had been, nor did I have any longer time..

    To the following you will find what you need for your further journeys into the world wide web upon my judgment following your question(s):


    • Learn HTML - you have less than sufficient knowledge about HTML, the httpd communication protocol, and the GET/POST methods of data transfer between you and the computer files (actually the daemon serving those files)
    • Learn DOM & Javascript - be a quick study if you're who say who you are, and learn that there are no IF COMMANDS in computer sciences. Look for "Control Structures" instead..
    • Learn Server-side Programming - or use of the XMLhttpdRequest otherwise you can't handle multiple requests (either incoming or outgoing). Perl will do the job..


    Here are the web sites you are encouraged to pursuit for beginning..


    I can only hope you (the page visitors) would find what was written here and above useful..

    regards..
    Last edited by kunter; 4th Dec 2009 at 12:46. Reason: I always re-edit
    - kunter ilalan web designer
    follow him on twitter and on MediaCollege

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Subscribe to us on YouTube