0

Here I have a popup window with table having 3 columns of Text Area and Dropdown1 and Dropdown2. Here user will enter the input data into text area and user will select the dropdown index values. And here One "SAVE" button is in popup window. After entering data and selecting dropdown options user needs to save this data in server.

Java script is for saving the data.


 <script type="text/javascript"> 
                $(document).ready(function () {
                    function savaasfile() {
                        //$("#savefile").click(function () {

                        var customer = document.getElementById("modaltable");
                        customer.name = $("[id*=textdata]").val();
                        customer.scramble = $("[id*=DropDownList2]").val();
                        customer.confirm = $("[id*=DropDownList1]").val();

                        $.ajax({
                            type: "POST",
                            url: "server path.txt",
                            data: JSON.stringify(customer),
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success: function (data) {
                                $('#myModal').dialog("close");

                            }
                        });
                        //function openSaveModal() {
                        //    $('#myModal').modal('show');
                        //}
                        //  customer.preventDefault();

                    }
                });
            </script>

**Button code**

    <button runat="server" id="savefile" class="btn btn-primary" onclick="savaasfile()" >Save </button>

After entering the data and while trying to save the data it is not performing anything. And it is closing automatically. While debugging the code it is saying like "no element found". What's wrong in the above code. What changes I have to make.

This is HTML code for Table and pop up window


 <div id="myModal" class="modal fade" role="dialog" data-keyboard="false" data-backdrop="static">
        <div class="modal-dialog">
                   <div class="modal-header" style="background-color: orangered; border-top-left-radius:4px; border-top-right-radius:4px;">
                 <div class="modal-body">
                    <table class="table .table-responsive" id="modaltable">
                        <thead>
                            <tr>
                                <th style="background-color: #333333; color: #FFFFFF;" colspan="1">Index Position</th>
                                <th style="background-color: #333333; color: #FFFFFF;">Type of Scrambler</th>
                                <th style="background-color: #333333; color: #FFFFFF;">Scrambling Required</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>
                                    <textarea class="form-control" id="textdata"></textarea></td>// input area
                                <td>
                                    <div class="dropdown">
                                        <asp:DropDownList ID="DropDownList2" runat="server" CssClass="selectpicker"> //dropdown index
                                            <asp:ListItem Text="Alpha-Numeric Scramble" /> 
                                            <asp:ListItem Text="Packed-Decimal Scramble" />
                                            <asp:ListItem Text="Date-Time Scrambler" />
                                        </asp:DropDownList>
                                    </div>
                                </td>
                                <td>
                                    <div class="dropdown"> //dropdown index
                                        <asp:DropDownList ID="DropDownList1" runat="server" CssClass="selectpicker">
                                            <asp:ListItem Text="Yes" />
                                            <asp:ListItem Text="No" />
                                        </asp:DropDownList>
                                    </div>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div class="modal-footer">
                    <button runat="server" id="savefile" class="btn btn-primary" onclick="savaasfile()" >Save </button>
                </div>
            </div>
        </div>
    </div>

Here is the full code of Modal popup window with having table with text area and 2 dropdown indexes. And it is having "Save" button. Here user will enter the data. That data need to store in the given path.

Rajshekar Reddy
  • 18,647
  • 3
  • 40
  • 59
kiran
  • 153
  • 1
  • 3
  • 15
  • 1
    Move the function outside the document.ready for one. To find the ID of the button, view the source of the page. ASP may change it for your – mplungjan May 09 '16 at 07:04
  • can you post html markup of popup window. – dreamweiver May 09 '16 at 07:08
  • How come `$("[id*=DropDownList1]")`? Why not `$('#DropDownList1')`? – zer00ne May 09 '16 at 07:10
  • Please provide your full code with html and java-script as well, so that i can clear you. – Banwari Yadav May 09 '16 at 07:16
  • I have updated HTML and Java script in my query. – kiran May 09 '16 at 07:23
  • @kiran what is your server code to save the data into the file?? All I see is you are directly calling a `.txt` file by passing data to it.. Which will do nothing... – Rajshekar Reddy May 09 '16 at 07:31
  • @Reddy. I didn't write any server code sir. – kiran May 09 '16 at 08:39
  • Which server code I have to write here. – kiran May 09 '16 at 08:50
  • @kiran you can use any server side language like php, c# , java etc.. and using this server code you can save the contents sent from ajax into a file. – Rajshekar Reddy May 09 '16 at 09:25
  • @Reddy: Can you please suggest any C# links for writing server side code please. – kiran May 09 '16 at 10:54
  • @kiran what is the end goal of your project?? Are you planning to host this website somewhere? – Rajshekar Reddy May 09 '16 at 10:56
  • @Reddy: Main goal is to protect the client data. We will allow user to select the data which user wants to protect. Here we will scramble the data based on user selection criteria.. For that in Popup window user will enter the position of value and will select which type of scramble user wants. Then after these details will be saved into server. Later user can open and review it. – kiran May 10 '16 at 05:57
  • @kiran ok I got it, So if you use c# code to achieve the above when you host your site on some server you might have to spend more money as .Net framework has to be added in the server and its not free, While using java or php its free and you just have to sped money on the server space and hosting.. According to this you can decide which server code to use.. – Rajshekar Reddy May 10 '16 at 06:33
  • @Reddy: OK Sir thanks. – kiran May 10 '16 at 06:42

0 Answers0