Created
May 22, 2018 14:36
-
-
Save lois6b/dac41572f862264b4512426aab4d7479 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>Español <img src="https://upload.wikimedia.org/wikipedia/en/thumb/9/9a/Flag_of_Spain.svg/23px-Flag_of_Spain.svg.png"/></p> | |
<p>Inglés <img src="https://upload.wikimedia.org/wikipedia/en/thumb/a/ae/Flag_of_the_United_Kingdom.svg/23px-Flag_of_the_United_Kingdom.svg.png"/></p> | |
<br> | |
<input type="text" name="toIng" onkeypress="save(this, event)"> | |
<input type="text" name="toEsp" onkeypress="save(this, event)"> | |
<br> | |
<p>Inglés <img src="https://upload.wikimedia.org/wikipedia/en/thumb/a/ae/Flag_of_the_United_Kingdom.svg/23px-Flag_of_the_United_Kingdom.svg.png"/></p> | |
<p>Español <img src="https://upload.wikimedia.org/wikipedia/en/thumb/9/9a/Flag_of_Spain.svg/23px-Flag_of_Spain.svg.png"/></p> | |
<br> | |
<textarea id="toIng"></textarea> | |
<textarea id="toEsp"></textarea> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.formatEng = function() { | |
return this.replace(".", "").split(",")[0].replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1\,") + (this.split(",")[1] ? "." + this.split(",")[1] : ""); | |
}; | |
String.prototype.formatEsp = function() { | |
return this.replace(",", "").split(".")[0].replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1\.") + (this.split(".")[1] ? "," + this.split(".")[1] : ""); | |
}; | |
function save(el, e) { | |
var output = document.getElementById(el.name); | |
if (e.key === 'Enter' || e.keyCode === 13) { | |
if (el.value.trim() != "") { | |
if (el.name == "toEsp") { | |
output.textContent += el.value.formatEsp() + "\n"; | |
} else { | |
output.textContent += el.value.formatEng() + "\n"; | |
} | |
el.value = ''; | |
} else { | |
el.value = ''; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
textarea { | |
width: 300px; | |
height: 100px; | |
border: 1px solid #ccc; | |
padding: 5px; | |
overflow: auto; | |
display: inline-block; | |
} | |
input { | |
width: 300px; | |
border: 1px solid #ccc; | |
padding: 5px; | |
display: inline-block; | |
} | |
p { | |
width: 300px; | |
padding: 5px; | |
display: inline-block; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment