简体   繁体   English

未捕获的TypeError:无法设置未定义的属性“操作”

[英]Uncaught TypeError: Cannot set property 'action' of undefined

I understand that action is undefined, but I don't know how to fix it. 我了解该操作是不确定的,但我不知道如何解决。

Here's my code, I'm try to have a table that adds, deletes and updates the selected row. 这是我的代码,我尝试使用一个表来添加,删除和更新所选行。 Add works, but update and delete I am having the action undefined problem with. 添加作品,但更新和删除我有操作未定义的问题。

 <script>   

    function changeRecord()
    {
        document.myForm.action='change.php';
        document.myForm.submit();
    }
        function deleteRecord()
        {
                document.myForm.action='delete.php';
                document.myForm.submit();
        }
</script>

<?php    

    $servername = "localhost";
    $username = "n00832038";
    $password = "Fall2015832038";
    $db = "n00832038";

$conn = mysqli_connect($servername, $username, $password, $db);

if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

        $query = "SELECT * FROM movies ";
        $results = mysqli_query($conn, $query);
    ?>
</head>
    <body>
    <form action="add.php" method="get">
    <table>
        <tr>
        <td>Movie Title: </td><td><input type='text' name='title'></td>
    </tr>
     <tr>
        <td>Release Type: </td><td><select name='type'>
                        <option value="theaters">Theaters</option>
                        <option value="direct">Direct to Video</option>
                        <option value="television">T.V.</option>
                    </select>
                </td>
    </tr>
     <tr>
        <td>Release Year: </td><td><input type='text' name='year'></td>
    </tr>
     <tr>
        <td>Remake: </td><td><input type='radio' name='remake' value='yes'> Yes</td>
                <td><input type='radio' name='remake' value='no'> No</td>
    </tr>
     <tr>
        <td>Based On A Book: </td><td><input type='radio' name='basedbook' value='yes'> Yes</td>
                    <td><input type='radio' name='basedbook' value='no'> No</td>
    </tr>
    <tr>    <td colspan='2'> <input type='submit' value='Add Record'></td>
    </table>
    <form action='' name='myForm' method= 'get'>
<?php

    echo "<table border='1'>";

    while($row = mysqli_fetch_row($results))

    {

        $MoviesID = $row[0];

        $Title = $row[1];

        $ReleaseType = $row[2];

        $ReleaseYear = $row[3];

        $Remake = $row[4];

        $BasedonBook = $row[5];

        echo "<tr>";

        echo "<td><input type='radio' name='movieID' value='$MoviesID'></td>";

                echo "<td>$Title</td>";

                echo "<td>$ReleaseType</td>";

                echo "<td>$ReleaseYear</td>";

                echo "<td>$Remake</td>";

                echo "<td>$BasedonBook</td>";

                echo "</tr>";

    }

    echo "</table>";

mysqli_close($conn);
?>

<input type='button' value='Delete Record' onClick='deleteRecord()'>

<input type='button' value='Update Record' onClick='changeRecord()'>

</form>
    </body>

You should make the following changes : 您应该进行以下更改:

JS : JS:

function changeRecord()
{
    document.getElementById("myForm").action='change.php';
    document.getElementById("myForm").submit();
}
function deleteRecord()
{
    document.getElementById("myForm").action='delete.php';
    document.getElementById("myForm").submit();
}

And HTML : 和HTML:

<form action="add.php" method="get" id="myForm">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM