Results 1 to 7 of 7

Thread: Search Based On Cookies

  1. #1
    Join Date
    Mar 2007
    Location
    Tarboro, NC
    Posts
    290
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default Search Based On Cookies

    Ok, I attempted to solve this one on my own and I came to the conclusion that I will have to render the entire page with JavaScript, which needless to say made me very unhappy. So I decided before I go ahead and do it, I'd ask you guys if there is an easier method.

    Problem:
    I have a page dedicated to searching and it has a set of radio buttons with onClick events to change where the search box is searching, I would like it to be that when click it sets a cookie and on refresh/revisit it will remember where you were searching. I also have a <span> tag which inside is whichever search engine you are using. I.e. "You are searching Google Search." I hope that it can remember that to, it also uses and onClick event. I was wondering if it was possible to do it without rendering the entire page in JavaScript, say something like the area for the form is inside a <span> or <div> tag so thatthe JavaScript can just output it.

    Code for the Search:
    Code:
    <form>
    Google it...<input name="searchselect" onClick="searchswitch_google();makeTxt('currentsearch','You are searching Google Search.');" value="google" type="radio" checked>
    <br>
    Yahoo! it...<input name="searchselect" onClick="searchswitch_yahoo();makeTxt('currentsearch','You are searching Yahoo! Search.');" value="yahoo" type="radio">
    <br>
    Microsoft Live! it...<input name="searchselect" onClick="searchswitch_live();makeTxt('currentsearch','You are searching Microsoft Live! Search.');" value="live" type="radio">
    <br>
    Ask it...<input name="searchselect" onClick="searchswitch_ask();makeTxt('currentsearch','You are searching Ask Search.');" value="ask" type="radio">
    </form>
    <br>
    <form name="search" method="get" action="http://www.google.com/search">
    <br>
    <input class="field" name="q" size="25" maxlength="255" type="text">
    <br>
    <input class="field" value="Search" type="submit">
    </form>
    Code That Makes The Search Work:
    Code:
    function searchswitch_google()
    {
    document.forms.search.action='http://www.google.com/search';
    }
    
    function searchswitch_yahoo()
    {
    document.forms.search.action='http://search.yahoo.com/search';
    }
    
    function searchswitch_live()
    {
    document.forms.search.action='http://search.live.com/results.aspx';
    }
    
    function searchswitch_ask()
    {
    document.forms.search.action='http://www.ask.com/web';
    }
    Code For The "Current Searching...":
    Code:
    <span id="currentsearch">You are searching Google Search.</span>
    Code That Makes "Current Searching..." Work:
    Code:
    function makeTxt(id,txt){
    var obj = document.getElementById(id);
    obj.firstChild?obj.firstChild.data=txt:obj.appendChild(document.createTextNode(txt))
    }
    Well, I'll wait.

    -Tim

  2. #2
    Join Date
    Oct 2005
    Posts
    86
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Tim,

    Did you solve this problem. If you did, would you mind sharing. I am looking for the same thing.

  3. #3
    Join Date
    Mar 2007
    Location
    Tarboro, NC
    Posts
    290
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default

    I have not found a solution. I abandoned it long ago, and just used a system where I eliminated the radio buttons, they were the main reasons I wanted it, the radio button would remain selected on refresh.

  4. #4
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Sorry I didn't see this back then..

    The simple solution is to set a cookie with isChecked and a value, then recall from that cookie on page load isChecked == 1 then google isChecked. etc.

    A php session could also work.

    However, I am not sure this will work if there is a default "checked" radio button already set...
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  5. #5
    Join Date
    Oct 2005
    Posts
    86
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    What I want to do is have a cookie like that is used on angieslist.com

    Whenever a user log in, it remembers what you signed last time and automatically defaut to that.

    Thank you so much.

  6. #6
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    So are you asking how to make such a cookie? I am confused.

    If so check out this link
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  7. #7
    Join Date
    Mar 2007
    Location
    Tarboro, NC
    Posts
    290
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default

    I didn't see Bliz's reply, thank anyways. Otherwise I would have considered trying again.

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
  •