John
John

Reputation: 1

ReferenceError: addPpl is not defined

I've looked through the codes but i can't find the error.

Called it in a button input name="Add People" type="button" onclick="addPpl()" value="Add People" />

ReferenceError: addPpl is not defined

<HTML>
    <BODY>        
    <input name="Add People" type="button" onclick="addPpl()" value="Add People" />
    <TABLE BORDER=1 CELLPADDING=6 id="myTable">
        <SCRIPT LANGUAGE="JAVASCRIPT" type="text/jquery" src="http://code.jquery.com/jquery-1.9.1.js">

        function addPpl() {
            var table = $("#myTable");
            var tr = $("<tr />");
            for (var i = 0; i < 5;) {
                i++
                var td = $('"<td width="22" align="left" valign="top">' + i + '</td><td width="344" align="left" valign="top"><font face="Verdana" size="2">  </td></tr>"');

                var inp = $('"<input name="people_no"' + i + ' type="text" id="people_no"' + i + ' value="-" size="40" /></font>"');
                td.append(inp);

                if (i < 5) {
                    for (var k = 0; k < 1; k++) {
                        i++
                        var td = $('"<td width="25" align="left" valign="top">' + i + '</td><td width="343" align="left" valign="top"><font face="Verdana" size="2">  </td></tr>"');

                        var inp = $('"<input name="people_no"' + i + ' type="text" id="people_"' + i + ' value="-" size="40" /></font> "');
                        td.append(inp);
                    }
                    tr.append(td);
                }
                table.append(tr);
            }
        }

        </SCRIPT>
    </TABLE>
</BODY>
</HTML>

Upvotes: 0

Views: 88

Answers (2)

konkked
konkked

Reputation: 3231

You have double " on the inside of the beginning of your strings, see edited example below.

Also includes a few other changes for the following reasons

It looks like you have the script in the table tag, put the script into the head portion of the document, and you are using the type text/jquery when you should be using text\javascript, change those two issues and see if that resolves the issue

Also as noted by @Mouser you need a separate tag for the jQuery reference

 <html>
    <head>
    <script language="javascript" type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script type="text/javascript">
      function addPpl(){

                var table = $("#myTable");

                    var tr = $("<tr />");
                        for(var i=0; i<5; ){
                        i++
                            var td = $('<td width="22" align="left" valign="top">' + i + '</td><td width="344" align="left" valign="top"><font face="Verdana" size="2">  </td></tr>');

                    var inp = $('<input name="people_no"'+i+' type="text" id="people_no"'+i+' value="-" size="40" /></font>');
                    td.append(inp);

                    if(i<5) {

                        for( var k=0; k<1; k++ ){
                            i++
                            var td = $('<td width="25" align="left" valign="top">' + i + '</td><td width="343" align="left" valign="top"><font face="Verdana" size="2">  </td></tr>');
                            var inp = $('<input name="people_no"'+i+' type="text" id="people_"'+i+' value="-" size="40" /></font>');
                            td.append(inp);
                        }
                        tr.append(td);
                    }
                table.append(tr);
            }
        }
        </script>
    </head>
    <body>


        <input name="Add People" type="button" onclick="addPpl()" value="Add People" />
        <table BORDER=1 CELLPADDING=6 id="myTable"></table>

    </body>
</html>

Upvotes: 0

Mouser
Mouser

Reputation: 13304

You are missing a script element.

This script element loads your jQuery:

 <SCRIPT LANGUAGE="JAVASCRIPT" type="text/jquery" src="http://code.jquery.com/jquery-1.9.1.js"> 

But after that you should open another script element script

You cannot put code into a script element that has a src attribute. That script element gets filled with the code from the source. If you want to put code on your page use a script element without a src

<script language="JavaScript">
    //your code goes here
</script>

Also you need to close the jQuery script element .

<SCRIPT LANGUAGE="JAVASCRIPT" type="text/jquery" src="http://code.jquery.com/jquery-1.9.1.js"></script>

Upvotes: 1

Related Questions