-3

I have an input where I will parse a number out of the text (has commas ect) when sending to the form. What is the easiest way to do this? Do I have to break the normal form submit behaviour and get the number out with a js function?

Adobe flex had a concept of an itemRenderer, which would render the value differently than an itemEditor, but I am not aware of an equivalent in HTML.

SuperUberDuper
  • 9,242
  • 9
  • 39
  • 72
  • You could get it out on `input` but yeah, you would need javascript somewhere down the line - what does this mean though? `when sending to the form` – StudioTime Feb 25 '17 at 12:49
  • pressing submit, whats with the random downvotes on this site. – SuperUberDuper Feb 25 '17 at 12:59
  • 1
    The downvotes are there because your question does not meet the standards described in [How to Ask a good question](http://stackoverflow.com/questions/how-to-ask). – trincot Feb 25 '17 at 13:02
  • @trincot shesh kebabs https://hackernoon.com/the-decline-of-stack-overflow-7cb69faa575d#.kk512na52 – SuperUberDuper Feb 28 '17 at 17:29
  • @SuperUberDuper just ask a good question within the community guidlines... or I guess you could just not and post that hackernoon article instead :) – chiliNUT Feb 28 '17 at 17:37

1 Answers1

0

Yes, you have to stop the form from sending.

const form = document.querySelector('form');
form.addEventListener('submit', e => {
  e.preventDefault();
  var numbers = e.querySelector('input').value.match(/\d+/g);
  // Do with numbers whatever you want
  // If you want to send it to the server, do it by Ajax request
  return false;
})
Doc999tor
  • 190
  • 3
  • 15
  • yeah but I'm kinda breaking the default form behaviour then. – SuperUberDuper Feb 28 '17 at 17:29
  • I wrote: "Do I have to break the normal form submit behaviour and get the number out with a js function?" The answer is yes, you have to break normal form behavior, because the normal behavior is designed for non JS sites. – Doc999tor Feb 28 '17 at 23:52