Forums

Simple JS lines on auto fill-in based on dropdown choice

CrystalFrontier 20 Jan, 2015
Dear all

Sorry if my particular query may have been answered elsewhere but I may just have difficulties in finding the right keywords.

I am adding up number of participants times two different multipliers to show in two alternative 'fees A' and 'fees B' textboxes. As a second step, the following dropdown lets you choose between choice A or B. Consequently, the choice made should be mirrored in the third and final 'total fee' box



I assume it would only take a few lines of custom JS. From all the ones I've bootlegged from this forum so far😉 I can't find any I can use in this case from my inventory.

Any help would be greatly appreciated.

Best regards from Germany

Chris
GreyHead 21 Jan, 2015
Hi Chris,

As you say it'a a few lines of JavaScript. And I think you'd use an if clause to check the value of the drop-down and calculate the total.

Bob
CrystalFrontier 21 Jan, 2015
Hello GreyHead,

yes, I've concluded it would be an if..then script, but unfortunately, I lack the mere basics of such trifle lines, which is why I've turned to the forum. Would it be too much to ask to give me a crude idea of what the code would look like? I'm also browsing JS resources but I don't know where to start and which commands this implies exactly.

Thanks a plenty.

Chris
CrystalFrontier 22 Jan, 2015
Hello again,

I've tried working on a code together with a friend to solve the above riddle, which seems easy enough to me, but we can't get our hands around it.

I use underscore as 'value' in the dropdown (With_accommodation). We made sure everything is case sensitive etc..

Where are we going wrong?

Thanks for any help

window.addEvent('domready', function() {
  $('category').addEvent('onchange', getTotal());
});

function getTotal(){
  if($('category').value == "With_accommodation"){
      $('fees').value = $('total').value;
     }

     if($('category').value == "Without_accommodation"){
      $('fees').value = $('total_no_acc').value;
     }else{
     $('fees').value = "";
     }
    
}


Best regards
Chris
This topic is locked and no more replies can be posted.