jecommera
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(func tion() {
convert('cm');
});
$("#select_in").click(func tion() {
convert('in');
});
function convert(metric) {
switch(metric){
case 'cm':
$('.mnumber').each(functio n() {
$(this).html(Math.round(pa rseInt($(t his).text( ))*2.54)+" cm");
});
break;
case 'in':
$('.mnumber').each(functio n() {
$(this).html(Math.round(pa rseInt($(t his).text( ))*0.39)+" in");
});
break;
}
}
});
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(func
convert('cm');
});
$("#select_in").click(func
convert('in');
});
function convert(metric) {
switch(metric){
case 'cm':
$('.mnumber').each(functio
$(this).html(Math.round(pa
});
break;
case 'in':
$('.mnumber').each(functio
$(this).html(Math.round(pa
});
break;
}
}
});
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
that works - thank you
Can you please explain how it works when you add two names?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
lol I did not see the first one...
I replaced click event by change event, the
I replaced click event by change event, the
most important part
I think
ASKER
There is already a name on the radio called metrics