Javascript – I keep getting a “Uncaught TypeError: string is not a function” error, even though the code seems to be fine. Can anyone have a look and explain

htmljavascript

<html>
    <head>
    <script language = javascript>
    show = function()
    {
         document.getElementById("name").innerHTML = window.opener.game.pl.guild.n;
         var app = document.getElementById("app");
         var apps = window.opener.game.pl.guild.app;

         for (a in apps)
         {
              var appAdd = document.createElement("option");
              appAdd.text = apps[a];
              appAdd.value = apps[a];

              app.add(appAdd);
         }
    }

    accept = function()
    {
        console.log("Accepting");
        var app = document.getElementById("app");

        window.opener.input.options = "acceptApp";
        window.opener.input.an = app.options[app.selectedIndex].value;
    }
    </script>
    </head>

    <body onload = "show()">
        <h1 id = "name" align = "center"> ### </h1>
    <div style="text-align:center">
            <p>You own this guild.</p>
        </div>
    </br>

        <p>Applications:</p>
        <select id = "app"></select>

        <input type = "button" onclick = "accept()" value = "Accept application" />
     </body>
</html>

Every time a user clicks the button, the accept function should be called. There's nothing wrong with the function itself, I'm sure about that. The function show that gets called when this starts just fills the selection with options, and create just sends it to the server.

Best Solution

You should put a semi-colon after the function call in your events:

 onload = "show();"

 onclick = "accept();"

Edit: I also see in these similar SO questions that there can be problems with function names that cause this exact error message. Just for fun, you might try renaming your functions...

Related Question