jquery - Changing value of variable based on elseif -


i new in stack, , new in jquery. found here reactions, collect these "calculator". it´s functional, there 1 problem, variable called "hodnota" isn´t changing value according elseif statement.

please, problem, don´t know anybody? :-)

simply need change value called "hodnota" based on variables values in "if conditions" , when select(.ninja-forms-field) changing...

my code here...

    <script> var vyska; var barva; var rozmery; var $hodnota = $(this.hash); var pocet;  rozmery=jquery("#ninja_forms_field_165 :selected").text(); barva=jquery("#ninja_forms_field_167 :selected").text(); vyska=jquery("#ninja_forms_field_166 :selected").text();   if(/200x200cm/i.test(rozmery)&&/140/i.test(vyska)&&/režná/i.test(barva)){ hodnota=2380; }else if(/200x200cm/i.test(rozmery)&&/150/i.test(vyska)&&/režná/i.test(barva)){ $hodnota=2480; }else if(/200x200cm/i.test(rozmery)&&/160/i.test(vyska)&&/režná/i.test(barva)){ $hodnota=2780; }else if(/205x205cm/i.test(rozmery)&&/140/i.test(vyska)&&/režná/i.test(barva)){ $hodnota=2480; }else if(/205x205cm/i.test(rozmery)&&/150/i.test(vyska)&&/režná/i.test(barva)){ hodnota=2580; }else if(/205x205cm/i.test(rozmery)&&/160/i.test(vyska)&&/režná/i.test(barva)){ $hodnota=2880; }else{ $hodnota=0; }  jquery('.ninja-forms-field').change(function(){ alert($hodnota); });   </script> 

here fiddle how solve problem... jsfiddle

function spocitejhodnotu() {      var rozmer = jquery('#ninja_forms_field_165 option:selected').text();     var vyska = jquery('#ninja_forms_field_166 option:selected').text();     var barva = jquery('#ninja_forms_field_167 option:selected').text();      var is200 = /200x200cm/i.test(rozmer);     var is205 = /205x205cm/i.test(rozmer);     var is140 = /140/i.test(vyska);     var is150 = /150/i.test(vyska);     var is160 = /160/i.test(vyska);     var isrezna = /režná/i.test(barva);     var isseda= /šedá/i.test(barva);     var issahara=/sahara/i.test(barva);     var iskhaki=/khaki/i.test(barva);     var is440=/režná 440g na m2/i.test(barva);       var hodnota = 0;      if (is200) {       if (is140) {         if (isrezna) {             hodnota=2380;          } else if(isseda){             hodnota=2520;         } else if(issahara){             hodnota=2520;         } else if(iskhaki){             hodnota=2600;         } else if(is440){             hodnota=3000;         }       }       if (is150) {         if (isrezna) {             hodnota=2480;          } else if(isseda){             hodnota=2620;         } else if(issahara){             hodnota=2620;         } else if(iskhaki){             hodnota=2700;         } else if(is440){             hodnota=3100;         }       }       if (is160) {         if (isrezna) {             hodnota=2780;          } else if(isseda){             hodnota=2920;         } else if(issahara){             hodnota=2920;         } else if(iskhaki){             hodnota=3000;         } else if(is440){             hodnota=3500;         }       }     }     if (is205) {       if (is140) {         if (isrezna) {             hodnota=2480;          } else if(isseda){             hodnota=2620;         } else if(issahara){             hodnota=2620;         } else if(iskhaki){             hodnota=2700;         } else if(is440){             hodnota=3100;         }       }       if (is150) {         if (isrezna) {             hodnota=2580;          } else if(isseda){             hodnota=2720;         } else if(issahara){             hodnota=2720;         } else if(iskhaki){             hodnota=2800;         } else if(is440){             hodnota=3250;         }       }       if (is160) {         if (isrezna) {             hodnota=2880;          } else if(isseda){             hodnota=3020;         } else if(issahara){             hodnota=3020;         } else if(iskhaki){             hodnota=3100;         } else if(is440){             hodnota=3600;         }       }     }         return hodnota;  }  // tohle se provede, pokud se změní nějaký select jquery('#ninja_forms_form_7').find('select').change(function () {     var hodnota = spocitejhodnotu();     alert(hodnota); });  // tohle se provede při načtení skriptu alert(spocitejhodnotu()); 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -