Javacsript text string converter
At work I had these strings that looked something like this:
{xxxxx-xxxxxxxxx-xxx-xxx-xxxxx-xxxxxx}
And I would need to remove the curly brackets and the hyphens and then paste the result into the HTML I was working with. This was, of course, obnoxious and super prone to human error. So I went ‘a searching and found resources (listed after the code) that gave me enough information that I was able to put together the following:
<!DOCTYPE html>
<html>
<body>
<p>
Enter your text then click the button below.
</p>
Name:
<input type="text"
id="IDString">
<button type="button"
onclick="imageIDConvert()">
convert
</button>
<p id="demo"></p>
<script>
// Here the value is stored in new variable x
function imageIDConvert() {
var stringInput =
document.getElementById("IDString").value;
var stringOutput = stringInput.replace(/-/g,"").replace(/{/g,"").replace(/}/g,"");
document.getElementById(
"demo").innerHTML = stringOutput;
}
</script>
</body>
</html>
https://www.geeksforgeeks.org/how-to-get-the-value-of-text-input-field-using-javascript/
https://www.w3schools.com/jsref/jsref_replace.asp
https://stackoverflow.com/questions/3293540/multiple-replaces-with-javascript
I’ve never touched Javascript before, so I’m feeling fairly pleased with myself!