I have a view with a form that stores some values in the database. Later I can open the record again and it passes the stored values by querystrings into the same view, filling the fields.
Works fine for text fields and dropdown, but I cannot make the same process for the checkboxes. The thing is, they all have to be in the same js var, into the same database field, into the same querystring, and then into the checkboxes again.
// for testing
function displayTest() {
var contacts = $('input[name="fieldtotest"]:checked').map(function () {
return this.value;
}).get();
$("#outputtest").val(contacts.join(","));
}
$(":checkbox").change(displayTest);
displayTest();
//gets all qs
function getParameterByName(name, url) {
if (!url) {
url = window.location.href;
}
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
var setmyfield = getParameterByName('myqsvar');
if (setmyfield) {
// something that selects the right checkboxes
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="form-group" align="left">
<div>
<label for="fieldtotest">Field to test</label>
</div>
<div>
<input type="checkbox" name="fieldtotest" value="John Smith">John Smith<br>
<input type="checkbox" name="fieldtotest" value="Joseph Augustine">Joseph Peter<br>
<input type="checkbox" name="fieldtotest" value="Sarah Smith">Sarah Smith<br>
<input type="checkbox" name="fieldtotest" value="Caroline Gabes">Caroline Gabes
</div>
</div>
<input type="text" id="outputtest" size="50">
If the field is a simple text box, I would pick the querystring and use
$('#fileldid').val(qsvalueforthefield)
to populate the field again, but I cannot do this for several checkboxes in a single var/qs. Is this possible?
updateable-checksto the checkboxes and use it to select the relevant DOM elements