Reputation: 13224
I want option ccc to be selectable, but not submitted, so when someone submit form with option ccc selected, all <select>
should not be sent.
HTML only solution would be best.
<select name="some">
<option>aaa</option> //send
<option>bbb</option> //send
<option special>ccc</option> //dont send
</select>
Upvotes: 0
Views: 2662
Reputation: 493
Using Only HTML you can
<form action="#" method="POST">
<select name="some" required>
<option selected value="">ccc</option> //empty value
<option value="aaa">aaa</option> //send
<option value="bbb">bbb</option> //send
</select>
<input type="submit" name="submit">
</form>
Upvotes: 0
Reputation: 6346
You cannot prevent the select
submission without removing or disabling it prior to form submission using javascript.
Having said that, it makes much more sense to test for this on the server side, and this is actually done regularly when no option is selected, like so:
<select name="some">
<option value="-1">Select an option</option>
<option value="aaa">aaa</option>
<option value="bbb">bbb</option>
</select>
PHP:
if ($_POST['some']!=-1) {
// do something
}
Upvotes: 1
Reputation: 1597
With HTML only, the field will always be submitted. However you can post an empty value, giving practically the same effect:
<select name="some">
<option value="aaa">aaa</option>
<option value="bbb">bbb</option>
<option value="">ccc</option> //empty value
</select>
Upvotes: 1
Reputation: 2523
Try this
<select name="some">
<option value="aaa">aaa</option> //send
<option value="bbb">bbb</option> //send
<option>ccc</option> //dont send
</select>
If I'm correct this should return nothing when you send the form with ccc selected.
Upvotes: -1