www.webdeveloper.com
Results 1 to 3 of 3

Thread: Multiple parameters through GET

  1. #1
    Join Date
    Jun 2010
    Posts
    6

    Multiple parameters through GET

    Ok I am pretty sure Javascript is the only way to do this...

    I need to pass more than one parameter from a form to a url

    For example:

    I need this output

    Code:
    http://mywebsite.com/index.php?price_min=10&price_max=20&sort=featured
    I would have no problem if I only needed
    Code:
    http://mywebsite.com/index.php?price=10
    Code:
    <form method="get" action="http://mywebsite.com/index.php"
    <select name="price">
    <option value="10" id="1">10</option>
    </select>
    </form>
    The problem comes because they both need to come from a single option

    I thought of hand coding it into the option boxes like this
    Code:
    select name="price_min"> 
    <option value="10&price_max=20">$10 to $20</option>
    Of course that doesn't work because of the url encode.

    So does any one know the javascript needed to achieve this?

    Any help is greatly appreciated!

  2. #2
    Join Date
    Jul 2009
    Posts
    45
    I would do the following:

    Code:
    ... <option value='10-20'>$10 thru $20</option> ...
    Then in the handling code (I'm assuming it will be PHP, and assuming the select field's name is price in this example):

    PHP Code:
    ...

    $price $_GET['price'];
    $price explode("-"$price);
    $min_price $price[0];
    $max_price $price[1];

    ... 
    OR in js:


    Add 2 hidden fields into the form, one named "min_price", the other named "max_price", and an onchange referece in the select name
    Don't forget to fill in the values for min_price and max_price (set the values to that of the first option in the select field), this could also be achieved through js with some more effort.

    Code:
    <select name='price' onchange="this.form.min_price = this.value.split('-')[0]; this.form.max_price = this.value.split('-')[1];">
        <option value='10-20'>$10 through $20</option>
        <option value='21-30'>$21 through $30</option>
    </select>
    <input type='hidden' name='min_price' value='10' />
    <input type='hidden' name='max_price' value='20' />
    Hope that helped.
    Last edited by ntk418; 12-29-2010 at 06:58 AM. Reason: bugfix

  3. #3
    Join Date
    Jun 2010
    Posts
    6
    The only problem with that script is that it still passes the values called price and 10-20 through.

    I need JavaScript to grab the select value then add the hidden value to submit the form, because the min and max price are the only thing thats changing they are not static.

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