Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I keep getting a "Uncaught TypeError: string is not a function" error, even though my code seems to be fine. Can anyone have a look and explain?

<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.

like image 435
corazza Avatar asked Jan 10 '12 21:01

corazza


People also ask

How do I fix uncaught TypeError is not a function?

The TypeError: "x" is not a function can be fixed using the following suggestions: Paying attention to detail in code and minimizing typos. Importing the correct and relevant script libraries used in code. Making sure the called property of an object is actually a function.

What does uncaught TypeError mean?

According to the Mozilla website for developer documents, “the TypeError object represents an error when a value is not of the expected type.” Uncaught means that the error was not caught in the catch part of the try-catch block.

What is uncaught type error in jQuery?

Kelly M. - September 27, 2020. The $ sign in jQuery is a syntax commonly used as a shortcut to access or define a JavaScript library. The code below illustrates that invoking the $ sign or the jQuery method results in all the <p> tags in a document.


1 Answers

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...

like image 198
DOK Avatar answered Sep 20 '22 12:09

DOK