HTML Select problem

H

howachen

Hi, is it possible to have a pre-defined value for select box which
mean "select nothing"?

e.g.


<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>

I want to have an option something like <option value="xxx">Please
Select</option>

and when the form get

it will shown in the query string only IF it was selected.

e.g.

test.php?car=Saab

but the default is just:

test.php
 
J

Jonathan N. Little

Hi, is it possible to have a pre-defined value for select box which
mean "select nothing"?

e.g.


<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>

I want to have an option something like <option value="xxx">Please
Select</option>


Well yes and no. You can certainly have a null value or a token that
means "none", then your receiving script would deal with it
appropriately, but the parameter will show in the query string:

<select name="cars">
<option value="none">Please Select</option>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>

....

test.php?car=none&otherParam=something

or

<select name="cars">
<option value="">Please Select</option>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
....

test.php?car=&otherParam=something

The only ways to prevent the param from being in your query string is to
use client-side javascript to remove it (or build the query string) But
this would be a bad idea because it will fail if the client has
javascript disabled. *I would not recommend it.*


The other is use POST instead of GET where the query is not in the URL.
Not sure from your brief snippet whether on not your form is selecting a
resource (GET is appropriate) or transmitting data (POST is appropriate).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top