0

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
asked Jul 30, 2014 at 11:26
1
  • What the sun going on? Commented Jul 30, 2014 at 11:33

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

Comments

1

Try using .change() when the select value is changed.

$( ".target" ).change(function() {
 // code here
});
answered Jul 30, 2014 at 11:36

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.