Reputation: 5013
I am converting a Mootools snip to jQuery and have an issue with value being returned as an object.
Mootools code
aVariable: function (elems, locks, hiddenInput, elem) {
initialValue = '';
if (elem) {
var val = elem.get('value').toFloat().round(2);
var v = val ? val : '0';
elem.set({
'value': v
});
Serialize.verifyInput(elems, elem, locks);
}
}
jquery bad try
aVariable: function (elems, locks, hiddenInput, elem) {
initialValue = '';
if (elem) {
var val = $(elem).get('value').toFloat().round(2);
var v = val ? val : '0';
$(elem).val(v);
Serialize.verifyInput(elems, elem, locks);
}
}
I know that $(elem) or $(this) returns an object where in Moo elem returns the string can someone shed some light on this please. Thank you!
Upvotes: 1
Views: 70
Reputation: 28837
As you might know, jQuery and Mootools can exist in the same page, anyway to answer your question, try this:
aVariable: function (elems, locks, hiddenInput, elem) {
initialValue = '';
var round = function (inputValue, precision) {
precision = Math.pow(10, precision || 0).toFixed(precision < 0 ? -precision : 0);
return Math.round(inputValue * precision) / precision;
}
if (elem) {
var val = round(parseFloat(elem.value),2);
var v = val ? val : '0';
elem.value = v;
Serialize.verifyInput(elems, elem, locks);
}
}
Upvotes: 1