2

I want to change the values of a select box based on the value in other in a Web Page.

When the page is loaded I store the keys and values in a hash. So when I change the value in field1 it calls javascript function and the values in field2 should change as per the hash.

Hash:

%hash = ('factory1','model1','factory2','model2','factory3','model3');

jQuery Function:

\$('#factory').change(function(){
                var factoryVal = \$(this).val();               
               \$('#model').val()="$hash{"+factoryVal+"}" ;
 });              

How can I do it?

1 Answer 1

3
use JSON;
my %hash = ('factory1','model1','factory2','model2','factory3','model3');
my $json_str = encode_json \%hash;

print qq{

  var hash = $json_str;

}, q{

  $('#factory').change(function(){
      var factoryVal = $(this).val();
      $('#model').val( hash[factoryVal] );
  });

};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.