2

I found this plugin for jQuery where you can type a number (let's say "650") and the input field would automatically change it to €650,-.

But when I submit the form, the form value is "€650,-" (not very suprising).

What I want is the functionality that the plugin would change it back to "650" on submitting the form. The inputs should only accept whole euro's, so "650,40" is not permitted.

Does anyone know how to accomplish this?

4
  • 1
    Could you post some code? Commented Jun 10, 2014 at 11:07
  • what jquery plugin you used? there is usually an api from the plugin to get the actual value.. Commented Jun 10, 2014 at 11:08
  • I saw this demo: decorplanit.com/plugin Commented Jun 10, 2014 at 11:10
  • I think this thread will help me: stackoverflow.com/questions/15815771/… I will try this first Commented Jun 10, 2014 at 11:13

4 Answers 4

2

This is what I used to answer this question:

$('form').submit(function(){ var form = $(this); $('input').each(function(i){ var self = $(this); try{ var v = self.autoNumeric('get'); self.autoNumeric('destroy'); self.val(v); }catch(err){ console.log("Not an autonumeric field: " + self.attr("name")); } }); return true; }); 

Thanks to:

autoNumeric.js remove formatting before submitting form

Sign up to request clarification or add additional context in comments.

Comments

1

You have to submit the form manually, for example if you have form like this...

<form name="f1"> <input type="text" id="autoNum"/> <input type="button" value="submit" onclick="onsubmit()"/> </form> <script> $(function() $("#autoNum").autoNumeric(); }); function onsubmit(){ $("#autoNum").val($("#autoNum").autoNumeric("get")); document.f1.submit(); } </script> 

We can get the value with out the currency symbol using the autoNumeric public method get.

1 Comment

can you provide the Fiddle for the same with alert value? Input String €650,-
1

Try this code on your server side, this works.

string x = "€650,-"; x = Regex.Replace(x, "[^0-9,]", ""); x = x.Split(',')[0]; 

Output:

650

Comments

1

Now this is possible with plugin default options.

new AutoNumeric(".money-val", { unformatOnSubmit: true }); 

After form submission, it automatically formatted again on mouse hover on input field.

unformatOnHover:true 

1 Comment

This is now the way to go with the latest version of AutoNumeric. However, if you want to submit the unformatted data, and stay on the same page with the formatted data in the form, then you'd prefer to use the specialized form functions like anElement.formSubmitNumericString(callback);. If you want to reformat all the unformatted values, just use anElement.formReformat();.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.