JavaScript Javascript replace function “is not a function” javascript replace function arguments,javascript replace function not working,javascript

I have an issue with the following code. I want to replace a string by another one, and generate an img code. However, I got an error message: str.replace is not a function. Any idea why?

    <input type="text" id="text">
    <input type="button" value="See Code" onclick="myFunction();">
    <input type="text" id="code" name="code">

<script>
    function myFunction() {
        var str = parseInt(document.getElementById("text").value);
        var res = str.replace("ftpadress", "htmladress");
        var code = str.concat("<img src='",res,"' width='100%'>");
        document.getElementById("code").value = code;
        }
</script>
Answer:1

Just remove the casting (parseInt function) and everything should work fine.

 <input type="text" id="text">
    <input type="button" value="See Code" onclick="myFunction();">
    <input type="text" id="code" name="code">

<script>
    function myFunction() {
        //changed
        var str = document.getElementById("text").value;
        console.log(str);
        var res = str.replace("ftpadress", "htmladress");
        var code = str.concat("<img src='",res,"' width='100%'>");
        document.getElementById("code").value = code;
        }
</script>
Answer:2

I have created a html dom structure like this. I have used the ng-click to toggle the visibility of the DOM structure. For example if I am clicking in menu1 and if it is not visible it will be make ...

I have created a html dom structure like this. I have used the ng-click to toggle the visibility of the DOM structure. For example if I am clicking in menu1 and if it is not visible it will be make ...

  1. toggle visibility html
  2. toggle visibility html element javascript
  3. toggle hide html
  4. toggle password visibility html
  5. toggle visibility javascript html
  6. toggle button visibility html
  7. toggle visibility of html element
  8. toggle visibility div html
  9. html toggle visibility without javascript
  10. html toggle visibility on click
  11. html toggle visibility jquery
  12. html toggle visibility checkbox

I am putting together an HTML5 form for music teachers so they can classify their music library a bit easier. One of the requested elements is a double handled range slider that would be able to ...

I am putting together an HTML5 form for music teachers so they can classify their music library a bit easier. One of the requested elements is a double handled range slider that would be able to ...

I have an JS collection (array of objects with few properties). let xyz = [{ categoryId: 1, categoryName: 'Test', programId: 112, programName: 'Program Test', value: 5050, ...

I have an JS collection (array of objects with few properties). let xyz = [{ categoryId: 1, categoryName: 'Test', programId: 112, programName: 'Program Test', value: 5050, ...

Functions that were polyfilled with core-js (for example, babel-polyfill) appear as native. Promise.race.toString() produces: function race() { [native code] } So does Object.values.toString(). ...

Functions that were polyfilled with core-js (for example, babel-polyfill) appear as native. Promise.race.toString() produces: function race() { [native code] } So does Object.values.toString(). ...

  1. core-js babel
  2. core-js babel-polyfill
  3. core-js babel 7
  4. core-js babel webpack
  5. core js babel config
  6. core-js babel-loader
  7. core-js vs babel-polyfill
  8. core-js/stable babel
  9. core-js vs babel
  10. core js 3 babel
  11. babel corejs option
  12. babel core-js version
  13. babel core-js missing
  14. babel core js 2
  15. babel core-js example
  16. babel core-js promise
  17. babel core-js/shim
  18. js babel-core/register