Link to home
Start Free TrialLog in
Avatar of jecommera
jecommeraFlag for United Kingdom of Great Britain and Northern Ireland

asked on

please help with my jquery

Hi,

The code below converts the div contents from cm to inch and visa versa.
How ever it does not work if someone keeps pressing the same radio button over and over.

Can someone advise how I can update my code to protect against this?

thanks

$(document).ready(function(){

       $("#select_cm").click(function() {
            convert('cm');            
      });
     
      $("#select_in").click(function() {
            convert('in');                  
      });

      function convert(metric) {

            switch(metric){
                 case 'cm':
                        
                      $('.mnumber').each(function() {
                          $(this).html(Math.round(parseInt($(this).text())*2.54)+" cm");
                      });
                      break;
                 case 'in':
                      $('.mnumber').each(function() {
                            $(this).html(Math.round(parseInt($(this).text())*0.39)+" in");
                       });
                      break;
            }
      }
});
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jecommera

ASKER

Hi

There is already a name on the radio called metrics
that works - thank you

Can you please explain how it works when you add two names?
with the same name radio button are exclusive and I replace click event by change event, the most important part I think
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
lol I did not see the first one...

I replaced click event by change event, the
most important part

Open in new window

I think