I have this bit of code that works great:
function displayVals() {
var phonevals = $("#bphonesel").val();
$('#bphone').val(phonevals);
}
$("select").change(displayVals);
displayVals();
I want to be able to reuse it for all the other select boxes I have on my site. So, I thought I'd use parameters to do it. However, I've so far been unable to get the syntax correct. Here's what I've got, but it doesn't work. Any help would be appreciated.
function displayVals(inputfld, boundfld) {
var nvenval = $(inputfld).val();
$(boundfld).val(nvenval);
}
$("select").change(displayVals());
displayVals('#bphonesel', '#bphone');
$.fn.displayVals = function(inputfld, boundfld) {
this.change(function() {
var nvenval = $(inputfld).val();
$(boundfld).val(nvenval);
}
}
$("select").displayVals();
Check out the jQuery docs on authoring plugins for more info.
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