I would like to generate the URL based on the form values. The problem is that when I click the submit button, I only get the partial URL up until the ?
, eg. base-url/comparison?
. I want the URL to have the form value concatenated to the end of base URL. How can I achieve this?
$('#generateCorrespondence').on('submit', function(e) {
e.preventDefault();
let id = $('#input-type').val();
let selection = $('#selection').val();
let method = $('#experimental-method').val();
let resolution = $('#structure-resolution').val();
if (id == 'loop_id') {
let formAction = $('#generateCorrespondence').attr('action');
let url = formAction + "id=" + selection;
$('#generateCorrespondence').attr('action', url);
console.log(url);
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form class="form-horizontal col-sm-12" id="generateCorrespondence" action="base-url/comparison?">
<div class="form-group col-sm-5">
<label for="ife">Choose Selection Type</label>
<select class="form-control" id="input-type">
<option value="loop_id">loop_id</option>
<option value="unit_id">unit_id</option>
</select>
<br />
<label for="selection">Enter Selection</label>
<input type="text" class="form-control" id="selection">
<br />
<label for="structure-resolution">Choose Equivalence Class Resolution Threshold</label>
<select class="form-control" id="structure-resolution">
<option value="4.0" selected>4.0</option>
<option value="1.5">1.5</option>
<option value="2.0">2.0</option>
<option value="2.5">2.5</option>
<option value="3.0">3.0</option>
<option value="3.5">3.5</option>
<option value="all">all</option>
</select>
<br />
<label for="experimental-method">Choose Experimental Technique</label>
<select class="form-control" id="experimental-method">
<option value="all" selected>Any</option>
<option value="xray">X-Ray</option>
<option value="em">Cryo-EM</option>
</select>
<br />
<button type="submit" id="submit_test" class="btn btn-primary">Submit</button>
</div>
</form>