SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Insert search variable with radio buttons

    o Keyword
    o Exact Phrase
    Search: |______________|

    [SUBMIT]



    I have an internal search bar with two radio buttons and an input box in which the radio buttons allow the user to do a general keyword search or search by an exact phrase. Pending on which radio is checked, will determine which search page it should go to.

    I am trying to insert the search criteria from an input box into the GET url in the radio value ie- /page.php?search="$search".

    How can I fill the below $search variable with the vaule from the input box on submit (see red areas below)?

    Code:
    <script type="text/javascript">
    function funct_WhereToGo()
    {
    var obj_RadioButton = window.document.theFORM.rb_Select;
    
    for (var i = 0; i < obj_RadioButton.length; i++)
    	{if (obj_RadioButton[i].checked == true)
    		{window.location = obj_RadioButton[i].value;}
    	}
    }
    </script>
    
    <form name="theFORM" method="get">
    <INPUT TYPE="RADIO" NAME="rb_Select" ID="rb_Select1" VALUE="/emt/test/member_emt2.php?search='$search'">
    Keyword<BR>
    <INPUT TYPE="RADIO" NAME="rb_Select" ID="rb_Select2" VALUE="/emt/test/member_emt3.php?search='$search'">
    Exact Phrase <br>
    
    <!--  the value of this input box needs to fill the above $search in red  -->
    <input name="search33" type="text" id="search33" size="27">
     
    
    <INPUT TYPE="BUTTON" onClick="funct_WhereToGo();" VALUE=">">
    </form>

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You're going about this the wrong way. The current radio buttons' value is probably a minor security concern. Your search page ought to be "search.php" and you should be passing the search keywords and what search type to use. So the URL would end up being:
    HTML Code:
    search.php?keywords=buffalo+meat+jerky&searchtype=exact
    Based on what radio button the user selected, you script should decide what sort of search to perform on the server side, i.e. with PHP. Give your form controls more meaningful names, since they will appear in the URL and nicer URLs do make a small impression. Also, some people (like me) like doing things by directly editing the URL.

  3. #3
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    813
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    agree, pretty url should be good design pattern to go about.


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
  •