Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need some help with my search box please ..

    Hi all, i would like some help with something if you would be so kind. I posted this in the php thread but was told (on another forum) that it is a javascript solution thats needed. He said:

    "make the onchange event of your select box call a js function that validates the selected value, changes the action of the form, and submits"

    Basically,

    I have this search box in my header ..




    With this code.

    <div style="padding:5px;">
    <form method="get" action="http://www.xxxxxxx.com/yyyyyy/">
    <table style="width:50%;" cellpadding="5">
    <tr>
    <td style="vertical-align:top;font-size:9pt;">
    input type="text" value="search ..." id="search" onkeyup="searchSel()">
    <SELECT id="groups">
    <option value="">Select:</option>
    <option value="user">Users</option>
    <option value="event">Events</option>
    <option value="gallery">Gallery</option>
    </select>
    <input type="submit" value="Go" class="mainmenu66" onmouseover="this.className='mainmenu77';" onmouseout="this.className='mainmenu66';"
    </div>
    </td>
    </tr>
    </table>
    </form>


    And am trying to do 2 things.

    1. Remove the 'go' button, and have it execute the search when the user selects an option from the drop down box.

    2. The 'action' of the form to goto a different place depending on the users selection within the drop down box -

    So; if they select 'Users'.. it goes to xxxxxx.com/searchusers, if they select events it goes to xxxxx.com/searchevents etc.

    Can anyone give me some ideas/code as to how i can implement this, Or, if anyone has some example code or something to help me along that would be awesome too? Have't had much luck with google when i searched for stuff ... my javascript knowledge is limited to a single university assignment so not very good, but not 100% noob .. just 90% hehe .

    Thanks to any and all who input into the thread

    Ric

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Something on these lines maybe

    PHP Code:
    <script type="text/javascript">
    <!--
    function 
    loadPage(obj){
    if(
    obj.options.selectedIndex!=0){
    location.href obj.options[obj.options.selectedIndex].value;
    }
    }
    //-->
    </script>

    <select name="s2" size="1" onchange="loadPage(this)">
    <option value="">Select</option>
    <option value="page1.htm">Link 1</option>
    <option value="page2.htm">Link 2</option>
    <option value="page3.htm">Link 3</option>
    </select> 
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #3
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Awesome man thanks so much!! Works perfectly

    One final question... i want to put "enter search ..." in the textarea, and when the user clicks to write something in there it clears the textarea first.

    Im going to give it a play now as i imagine its a very small amount of code but if anyone knows off the top of their head plz write it here

    And thanks again!!

  • #4
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    edit: nevermind fixed this issue.. just the one before it left. Thanks.
    Last edited by teamv; 08-31-2006 at 03:27 AM.


  •  

    Posting Permissions

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