I have a function for updating multiple selects based on values of another select.
How can I edit this function to use it without prototype just with jquery ?
function replace(val) {
if (val != 0) {
$$('select.replace).each(function(e) {
var aa = e.value.split("_");
if (aa[0] = val) {
e.value = val + "_" + aa[1] + "_" + aa[2];
jQuery("select.replace").trigger("chosen:updated");
}
});
} else {
alert('Please select a valid value');
return false;
}
}
Bergi
671k162 gold badges1k silver badges1.5k bronze badges
-
What the sun going on?Bhojendra Rauniyar– Bhojendra Rauniyar2014年07月30日 11:33:18 +00:00Commented Jul 30, 2014 at 11:33
2 Answers 2
It's simple:
jQuery( 'select.replace' ).each(function() {
var aa = $( this ).val().split("_");
if (aa[0] = val) {
$( this ).val( val + "_" + aa[1] + "_" + aa[2] );
//...
Red more about jQuery val() method.
answered Jul 30, 2014 at 11:28
antyrat
27.8k9 gold badges78 silver badges77 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Try using .change() when the select value is changed.
$( ".target" ).change(function() {
// code here
});
Comments
lang-js