如何在主页面中保存模态弹出值

时间:2016-06-23 10:06:02

标签: javascript c# jquery

我正在尝试将在模态弹出窗口中输入的数据保存到主页面。     这是主页面的代码。                                       公司信息                          

                <div id="AddMoreDetails">
                    <div class="table" runat="server" id="AddMore">
                        <div class="col-md-4">
                            <div class="row">
                                <div class="col-md-12">
                                    <table style="width:200%;">
                                        <tr>
                                            <td>Company Name</td>
                                            <td>Company Address</td>
                                            <td>Contact</td>
                                            <td>Company HO</td>
                                            <td>HO Contact</td>
                                            <td>Email ID</td>

                                        </tr>
                                        <tr>
                                            <td>
                                                <textarea id="TextArea1"></textarea>
                                            </td>
                                            <td>
                                                <textarea id="TextArea2"></textarea>
                                            </td>
                                            <td>
                                                <textarea id="TextArea3"></textarea>
                                            </td>
                                            <td>
                                                <textarea id="TextArea4"></textarea>
                                            </td>
                                            <td>
                                                <textarea id="TextArea5"></textarea>
                                            </td>
                                            <td>
                                                <textarea id="TextArea6"></textarea>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </div>
                    <div class="col-md-12" style="text-align: right">
                    <div class="row">
                        <div class="col-md-12">

以下是模态弹出窗口

的代码
<div id="myModalPopup" class="modal fade" role="dialog" data-keyboard="false"> // modal popup window
                        <div class="modal-dialog">
                             <div class="modal-content">
                                <div class="modal-header" style="background-color: orangered; border-top-left-radius: 4px; border-top-right-radius: 4px;">
                                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                                    <h4 class="modal-title">Company Details</h4>
                                </div>
                                <div class="modal-body">
                                    <asp:Panel ID="Panel2" runat="server" class="tab-pane">
                                        <div class="col-sm-12">
                                            <div class="row">
                                                <div class="col-sm-4">
                                                    <asp:Label runat="server" ID="lblNmeComp" Text="Name of Company" AssociatedControlID="txtNmeComp" CssClass="control-label" />
                                                    <asp:TextBox runat="server" ID="txtNmeComp" CssClass="form-control" />
                                                    <br />
                                                </div>
                                                <div class="col-sm-4">
                                                    <asp:Label runat="server" ID="lblAdrComp" Text="Adress of Company" AssociatedControlID="txtAdrComp" CssClass="control-label" />
                                                    <asp:TextBox runat="server" ID="txtAdrComp" CssClass="form-control" />
                                                    <br />
                                                </div>
                                                <div class="col-sm-4">
                                                    <asp:Label runat="server" ID="lblConctComp" Text="Contact Number" AssociatedControlID="txtConctComp" CssClass="control-label" />
                                                    <asp:TextBox runat="server" ID="txtConctComp" CssClass="form-control" />
                                                    <br />
                                                </div>
                                            </div>
                                        </div>

以下是打开模态弹出窗口的按钮代码

                            <button id="AddMore_Button" class="btn btn-primary" data-target="myModalPopup">Add More</button>   </div>

Here is the button code for saving data from modal popup window.

<button type="button" runat="server" onclick="savepopupdata()">

为了从模态弹出窗口中获取值,我编写了一个javascript函数。

<script type="text/javascript"> //Java script function
        function savepopupdata()
        {
            document.getElementById.valueOf(txtNmeComp) = document.getElementById.valueOf(TextArea1);
            document.getElementById.valueOf(txtAdrComp) = document.getElementById.valueOf(TextArea2);
            document.getElementById.valueOf(txtConctComp) = document.getElementById.valueOf(TextArea3);

        }
    </script>

但不幸的是,它没有保存数据。这段代码中有任何错误。

2 个答案:

答案 0 :(得分:1)

我们可以通过它的属性获取输入元素值,如ID,Class ... 试试

document.getElementById("TextArea1").value;

...

答案 1 :(得分:0)

如果您想按ID找到元素并更改其值,请尝试使用此代码

function savepopupdata() { 
    document.getElementById('txtNmeComp').value = document.getElementById('TextArea1').value;
    document.getElementById('txtAdrComp').value = document.getElementById('TextArea2').value; 
    document.getElementById('txtConctComp').value = document.getElementById('TextArea3').value;
}