0

I have a html select list where one can chose an option.

<select name='price' id='price'>
                <option value='' >Select....</option>
                <option value='0-50,000'>0-50,000</option>
                <option value='50,000-100,000'>50,000-100,000</option>
                <option value='100,000-150,000'>100,000-150,000</option>
                <option value='150,000-200,000'>150,000-200,000</option>
                <option value='200,000 and above'>200,000 and above</option>
                <option value='see all'>See All</option>
</select>

When this list is submitted via a html submit button, this list shows again in another page. Now, I want the option the user selected to be new selected value. I am doing this:

<select name='price' id='price'>
                <option value='{$_POST['price']}'>{$_POST['price']}</option>
                <option value='0-50,000'>0-50,000</option>
                <option value='50,000-100,000'>50,000-100,000</option>
                <option value='100,000-150,000'>100,000-150,000</option>
                <option value='150,000-200,000'>150,000-200,000</option>
                <option value='200,000 and above'>200,000 and above</option>
                <option value='see all'>See All</option>
 </select>

But values are appearing twice. The option the user selected is shown as the selected and still appears in the list. For example, we now have something like this:

0-50,000 (this is the selected value)
0-50,000
50,000-100,000
100,000-150,000
150,000-200,000
200,000 and above

How do I solve this?

3
Contributors
3
Replies
14
Views
2 Years
Discussion Span
Last Post by Szabi Zsoldos
0

For the second page, remove the <option value='{$_POST['price']}'>{$_POST['price']}</option>, then in each of the option, add an if statement to check if the $_POST['price'] is with the option value. If the value is matched, add the attribute 'selected' to that option.

0

Can you help me with a sample? I can't figure that out. Thanks

0
//Try this

    <select name='price' id='price'>
        <option <?=((isset($_POST['price']) && $_POST['price'] == '')?'SELECTED="SELECTED"':'')?> value='' >Select....</option>
        <option <?=((isset($_POST['price']) && $_POST['price'] == '0-50,000')?'SELECTED="SELECTED"':'')?> value='0-50,000'>0-50,000</option>
        <option <?=((isset($_POST['price']) && $_POST['price'] == '50,000-100,000')?'SELECTED="SELECTED"':'')?> value='50,000-100,000'>50,000-100,000</option>
        <option <?=((isset($_POST['price']) && $_POST['price'] == '100,000-150,000')?'SELECTED="SELECTED"':'')?> value='100,000-150,000'>100,000-150,000</option>
        <option <?=((isset($_POST['price']) && $_POST['price'] == '150,000-200,000')?'SELECTED="SELECTED"':'')?> value='150,000-200,000'>150,000-200,000</option>
        <option <?=((isset($_POST['price']) && $_POST['price'] == '200,000 and above')?'SELECTED="SELECTED"':'')?> value='200,000 and above'>200,000 and above</option>
        <option <?=((isset($_POST['price']) && $_POST['price'] == 'see all')?'SELECTED="SELECTED"':'')?> value='see all'>See All</option>
    </select>

Edited by Szabi Zsoldos

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.