JSFiddle - React, Tailwind, and code Playground
HTML
<form name="categoryform" method="post">
Category:<select name="category" id="category" >
<option value="games">games</option>
<option value="books">books</option>
<option value="toys">toys</option>
<option value="clothes">clothes</option>
</select>
Age: <select multiple="multiple" name="age" id="age" >
<option value="5">5</option>
<option value="10">10</option>
<option value="15">15</option>
</select>
<input id="submit" type="submit" name="submit" value="submit"/>
<div class="url"> </div>
</form>
CSS
.sel{
background:red;
}
JavaScript
//Generate url for category
$("select[name='category']").change(function(e) {
e.preventDefault();
var a = "http://localhost/childzone/";
$("div.url").append(a + this.value);
});
//Generate URL for the multi-select age list
var foo = [];
var a = "http://localhost/childzone/clothes&age=";
var b = '';
$("select[name='age']").change(function(e) {
e.preventDefault();
$("select[name='age'] :selected").each(function(i, selected) {
foo[i] = $(selected).text();
if (b == '') b = b + foo[i]; //if more than one option selected, seperate it by comma.
else b = b + ',' + foo[i];
});
$("div.url").html(a + b); //Append URL to div for reference
b = ''; //Clear the string holding URL.
});