I have two text fields and whenever I write a number in the first one, it should give me its name on the second field.
Let’s say I write 11 on the “first” field, then it should automatically put the word ‘eleven’ (NOT number itself) on the “second” field. And the same thing with any number.
I know this can be done with jQuery but I just don’t know how.
Any suggestions??
To relate two strings, it’s easiest to use an object to create a dictionary/ map, as shown below;
You can see this in action here: http://www.jsfiddle.net/dCy6f/
For more advanced behaviour:
You can test this inplementation here: http://www.jsfiddle.net/H6skz/
If you want the second value only to update when the user has finished typing into the first input field, change “keyup” to “change”.
To abstract this into a function, your could do:
and then use it as follows:
For a more intuitive interface, write a jQuery plugin:
and then use as follows: