I currently have the following code to update a URL. How do I combine this into something more robust so that I'm not repeating myself 3 times basically. I only want this to update when one of the fields is changed.
$(document).ready(function(){
$('#device_select').change(function() {
var device = $(this).val();
var face = $('#face_select').val();
var position = $('#position_select').val();
document.getElementById("add_dev_rack").href="127.0.0.1:8080/dcim/devices/"+device+"/edit/?face="+face+"&position="+position;
});
$('#face_select').change(function() {
var device = $('#device_select').val();
var face = $(this).val();
var position = $('#position_select').val();
document.getElementById("add_dev_rack").href="127.0.0.1:8080/dcim/devices/"+device+"/edit/?face="+face+"&position="+position;
});
$('#position_select').change(function() {
var device = $('#device_select').val();
var face = $('#face_select').val();
var position = $(this).val();
document.getElementById("add_dev_rack").href="127.0.0.1:8080/dcim/devices/"+device+"/edit/?face="+face+"&position="+position;
});
});
$('#position_select, #device_select, #face_select').change(function() {
var device = $('#device_select').val();
var face = $('#face_select').val();
var position = $('#position_select').val();
document.getElementById("add_dev_rack").href="127.0.0.1:8080/dcim/devices/"+device+"/edit/?face="+face+"&position="+position;
});
Have you tried somethign like this?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With