I'm having trouble redirecting the user after submitting a form. The form serves to allow the user to filter out doctors based on location, rating, and specialty. Here is my code for the form and javascript function:
<form onsubmit="getDoctors()" id="searchForm">
<div>
<div class="col-sm-3">
<div class="form-group">
<label for="specialty">Specialty:</label>
<select class="form-control" id="specialty">
<option value="">Select</option>
<% specialtyList.forEach(function(specialtyValue){%>
<option value="<%= specialtyValue %>"><%= specialtyValue %></option>
<% }); %>
</select>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label for="rating">Min. Rating:</label>
<select class="form-control" id="rating">
<option value="">Select</option>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label for="location">Location:</label>
<select class="form-control" id="location">
<option value="">Select</option>
<% locationList.forEach(function(locationValue){%>
<option value="<%= locationValue %>"><%= locationValue %></option>
<% }); %>
</select>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<input type="submit" class="btn btn-success" value="Search">
</div>
</div>
</div>
</form>
function getDoctors() {
var specialty = document.getElementById('speciality');
var rating = document.getElementById('rating');
var location = document.getElementById('location');
window.location.href("/doctors?specialty=" + specialty.options[specialty.selectedIndex].text + "&rating=" + rating.options[rating.selectedIndex].text + "&location=" + location.options[location.selectedIndex].text);
}
However, when I submit the form, all it does to the URL is put an empty query string: /doctors?
Does anyone know why this is happening? Any help is much appreciated.
urlencodebefore pass tohref, Refer this link sitepoint.com/jquery-decode-url-string