bm4499 Posted March 10, 2011 Share Posted March 10, 2011 Does anyone know how to modify this code so that it deny in case a text field is empty? Next to that I want to multiply it by 1.5. Anyone? onchange="document.getElementById('total').value = parseInt(document.getElementById('f1').value) + parseInt(document.getElementById('f2').value) + parseInt(document.getElementById('f3').value) + parseInt(document.getElementById('f4').value);" thanks a lot in advance! Link to comment https://forums.phpfreaks.com/topic/230188-problem-with-adding-values-and-multiplication/ Share on other sites More sharing options...
nogray Posted March 10, 2011 Share Posted March 10, 2011 In your case, I'll make a function that will check the value and return the integer or a 0; e.g. function my_parse_int(val){ val = parseInt(val, 10); if (isNaN(val)) return 0; return val; }; ... change the onchange event to onchange="document.getElementById('total').value = (my_parse_int(document.getElementById('f1').value) ....) *1.5; Link to comment https://forums.phpfreaks.com/topic/230188-problem-with-adding-values-and-multiplication/#findComment-1185828 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.