0

I'm so close to create my form i need. But there is still a "bug". I wan't create a form where a customer can calucate how expensive something will be. I'm sure there are a lot of shorter ways to build the whole thing, but this is not the question. The problem is the calucation:

When you choose: CMS it sets the Price 100, the you add "Contao" and it sets correctly to 350. But then when you no choose "Statisch" the Amount of 250 of the "Contao" isn't override to 0 again.

I hope you understand what i mean :D complicated to explain. I thank you a lot for you help.

JSFiddle.com Snippet

I think the Problem has to be in this part:

$(this).change(function(){
var ifCMS_val = $('input[name="ifCMS"]:checked').val();
var chooseCMS_val = $('input[name="chooseCMS"]:checked').val();
 ifCMS_cost = 0;
 chooseCMS_cost = 0;

    if(ifCMS_val == "ifCMSyes")
    {
        ifCMS_cost = 100;
        chooseCMS_cost = 0;
    }
    else if(ifCMS_val == "ifCMSno"){
         ifCMS_cost = 0
         chooseCMS_cost = 0;
    }

    if(chooseCMS_val == "Contao"){
        chooseCMS_cost = 250;
    }
    else
    {
        chooseCMS_cost = 0;
    }


summe =  chooseCMS_cost ;


$('#summehtml').html(summe)



}); 

2 Answers2

0

Just add a comprobation when you set the chooseCMS_cost

...
if(chooseCMS_val == "Contao" && ifCMS_val == "ifCMSyes"){
...

Otherwise you're adding 250 if "Contao" was previously selected.

Fiddle

acontell
  • 6,792
  • 1
  • 19
  • 32
0

Because

if(chooseCMS_val == "Contao"){
        chooseCMS_cost = 250;
    }
    else
    {
        chooseCMS_cost = 0;
    }

chooseCMS_val is still Contao this value doesn't get reset

you need to reset this set of radio inputs when the first ifCMS lot change

rogy
  • 440
  • 6
  • 23
  • oke, thanks for the idear. i found that snipped of code: $('input[name="chooseCMS"]').removeAttr('checked'); Problem: it only works after the second time clicked on the first radio button. – Fabrizio Cocco Jan 18 '15 at 16:39