I have the following JS code and I'm wondering how I can add a function to strip commas and $ from the number fields. Otherwise if someone adds 10,000 or $10000 or $10,000 I get a NaN output on most of the fields. I don't have much knowledge with JS just an FYI.
$(function() {
$('#loan_payoff_1').change(rekenen1);
$('#loan_payoff_2').change(rekenen1);
$('#loan_payoff_3').change(rekenen1);
$('#loan_payoff_4').change(rekenen1);
$('#loan_payoff_5').change(rekenen1);
$('#loan_payoff_6').change(rekenen1);
$('#loan_payoff_7').change(rekenen1);
$('#loan_payoff_8').change(rekenen1);
$('#loan_payoff_9').change(rekenen1);
$('#loan_payoff_10').change(rekenen1);
});
function rekenen1(){
var subtotal = Number($('#loan_payoff_1').val()) + Number($('#loan_payoff_2').val()) + Number($('#loan_payoff_3').val()) + Number($('#loan_payoff_4').val()) + Number($('#loan_payoff_5').val()) + Number($('#loan_payoff_6').val()) + Number($('#loan_payoff_7').val()) + Number($('#loan_payoff_8').val()) + Number($('#loan_payoff_9').val()) + Number($('#loan_payoff_10').val());
$('#subtotal').val(subtotal);
$('#confee').val(subtotal*0.01);
$('#flatrate').val(295);
var grandtotal = Number($('#flatrate').val()) + Number($('#confee').val());
$('#grandtotal').val(grandtotal);
$('#onetotal').val(grandtotal*0.38);
$('#twototal').val(grandtotal*0.62);
};
Try this: http://www.27seconds.com/kb/article_view.aspx?id=31
You can do it server-side with PHP if you like
http://www.crainbandy.com/programming/function-to-remove-all-non-numeric-characters-in-php
You can do it server-side with PHP if you like
http://www.crainbandy.com/programming/function-to-remove-all-non-numeric-characters-in-php
Is this going to do it in real time? I can't get it to work... Here's what I'm working with: http://jsfiddle.net/3dGEA/1/
Hi,
Server side is better but will work only after the form is submitted, you may try the code below (not tested):
The code above should be triggered by some event, like "change" event or "submit" event or whatever you want.
Regards,
Max
Server side is better but will work only after the form is submitted, you may try the code below (not tested):
$('field_id').get('value').replace(/(,|$)/g, '');
The code above should be triggered by some event, like "change" event or "submit" event or whatever you want.
Regards,
Max
I found this code and it works great. Although it removes the decimal. Could you guys offer a helping hand in helping prevent this.
<script type="text/JavaScript">
function valid(f) {
!(/^[A-zÑñ0-9]*$/i).test(f.value)?f.value = f.value.replace(/[^A-zÑñ0-9]/ig,''):null;
}
</script>
</head>
<body><br>
<form id="myform" action="">
<input name="mytext" type="text" onkeyup="valid(this)" onblur="valid(this)">
</form>
</body>
</html>
Can anyone help with this?
This topic is locked and no more replies can be posted.