Reputation: 1805
I have several selects on my page with names sport
and processed
. When I select in first select Soccer
and in second - true
I have this request to server: http://localhost/?sport=1&processed=true
.
My question is:
1) is it possible to ignore All
options in both selects. So, when I select All
in both or one selects the select value is ignored in request.
For example:
| Sport | Processed | request |
|--------|-----------|------------------------------------------|
| All | All | http://localhost/ |
| Soccer | All | http://localhost/?sport=1 |
| All | yes | http://localhost/?processed=true |
| Soccer | yes | http://localhost/?sport=1&processed=true |
2) is it possible to use only HTML and don't use JavaScript?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="http://localhost" method="get">
<p>
<select name="sport" title="Sport">
<option value="">All</option>
<option value="1">Soccer</option>
<option value="2">Tennis</option>
</select>
</p>
<p>
<select name="processed" title="Processed">
<option value="">All</option>
<option value="true">yes</option>
<option value="false">no</option>
</select>
</p>
<p>
<input type="submit" value="Send">
</p>
</form>
</body>
</html>
Upvotes: 0
Views: 2168
Reputation: 285
I don't think it can be done without javascript. A javascript solution might be to remove or disable the select tag from form at the time of submit if the selected value is an empty string.
<script type="text/javascript">
$(function(){
$(':submit').click(function(){
$('select').each(function(){
if ( $(this).val() == '' )
{
$(this).remove(); // or $(this).attr('disabled','disabled');
}
});
});
});
</script>
Upvotes: 2