HTML / CSS:使用JS将数据从form1复制到form2

时间:2012-01-02 19:21:12

标签: javascript forms html5

我有一个问题,我似乎无法弄清楚,过去两天一直看着它......

我正在测试,所以我的JS函数从form1复制到form2工作。它确实如此。

如果你看小提琴,我只粘贴了必要的代码。

  • name="txtTitle"复制name="hidTitle"的输入类型。
  • name="txtCount"的输入类型不会从name="hidCount"复制。

但它应该有效,因为它的代码基本相同?

http://jsfiddle.net/mVfZa/7/

1 个答案:

答案 0 :(得分:1)

来自你的JSFiddle - 我认为这是一个简单的错误。你写了 formDel.hidSoundeFileName代替formDel.hidSoundFileName

删除多余的“e”,你应该没问题。 下面是我的工作实例。如果我错过了什么,请告诉我。

<!DOCTYPE html>
<html>
    <head>

        <script type="text/javascript">
            function copyEditDeleteSongFormData(formDel, formUpd) {
                formUpd.txtTitle.value = formDel.hidTitle.value;
                formUpd.fileSoundFileName.value = formDel.hidSoundeFileName.value;
                formUpd.txtCount.value = formDel.hidCount.value;
                formUpd.txtTitle.value = formDel.hidTitle.value;
            }

        </script>
    </head>
    <body>

        <form action="adminSong.php" method="post" name="frmNewUpdateSong" id="fUpdateSong" enctype="multipart/form-data"
              onsubmit="return verifySongDetails(this)" action="adminSong.php">
            <fieldset>
                <legend>New/Edit Songs</legend>
                Artist
                <br>
                <select name="cboArtist" id="ddList">
                    <option value=''></option>
                    <option value='test1'>test1</option>
                    <option value='test2'>test2</option>
                    <option value='test3'>test3</option>
                </select><br>
                Song
                <br>
                <input type="text" name="txtTitle" id="txTitle">
                <br>
                <input type="file" name="fileSoundFileName">
                <br>
                <br>
                Count
                <br>
                <input type="text" name="txtCount">
                <br>
                <input type="submit" name="btnSave" value="Save"/>
                <input type="button" name="btnReset" value="Reset" onclick="resetNewUpdateSongFormData(this.form)"/>
                <br>
                <input type="hidden" name="hidId">
                <input type="hidden" name="hidSoundFileName">
                <br>
            </fieldset>
        </form>
        <br>


        <form action="#" method="post" name="frmEditDeleteSong" id="fDeleteSong" enctype="multipart/form-data">
            <fieldset>
                <legend>Stored Songs</legend>
                id: <br/>
                artistid:<br/>
                title:<br/>
                sound:<br/>
                count:<br/>
                changedate:<br/>
                <input type="hidden" name="hidId">
                <input type="hidden" name="hidArtistId" value="">
                <input type="hidden" name="hidTitle" value="Songtest">
                <input type="hidden" name="hidCount" value="Count123">
                <input type="hidden" name="hidSoundFileName">

                <br>
                <input type="button" name="btnEdit" value="Edit"
                       onclick="copyEditDeleteSongFormData(this.form, frmNewUpdateSong)"/>
                <input type="submit" name="btnDelete" value="Delete" onclick="verifyDeleteOfSong(this.form)"/>
                <br>

            </fieldset>
        </form>
    </body>
</html>