简体   繁体   中英

Save the modal popup data using jQuery

Here I have a popup window with one text area and 2 dropdown index. In popup window user needs to enter data. Then this data has to be stored in given path.

jQuery

$("#saveasfile").click(function () {
    var customer = {};
    customer.name = $("[id*=comment]").val();
    customer.scramble = $("[id*=DropDownList2]").val();
    customer.confirm = $("[id*=DropDownList1]").val();
    $.ajax({
        type: "POST",
        url: "D:\Scramble.txt",//path
        data: JSON.stringify(customer),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (r) {
            $('#myModal').dialog("close");//modal popup window
           // alert("Record inserted successfully.");
        }
    });
    });
</script>

Table design for modal popup:

<textarea class="form-control" id="comment"></textarea>
    </td>
        <td>
            <div class="dropdown">
                <asp:DropDownList ID="DropDownList2" runat="server" CssClass="selectpicker">
                    <asp:ListItem Text="Alpha-Numeric Scramble" />
                    <asp:ListItem Text="Packed-Decimal Scramble" />
                    <asp:ListItem Text="Date-Time Scrambler" />
                </asp:DropDownList>
            </div>
            <div class="dropdown">
                <asp:DropDownList ID="DropDownList1" runat="server" CssClass="selectpicker">
                    <asp:ListItem Text="Yes" />
                    <asp:ListItem Text="No" />
                </asp:DropDownList>

And having a button with "savefile" id.

Here is the Button code:

<button runat="server" id="Saveasfile" class="btn btn-primary" OnClick="saveasfile()">Save </button>

By clicking the "Save" button the user should save the data which is entered in the table rows.

While clicking the "Save" button it is closing automatically. While debugging it is showing like "No element found".

What should I do?

Html ids should be case sensitive in most browsers, as far as I know. You have

Saveasfile

and are trying to get

saveasfile

.Ajax can not write your data in to file. To write your data in to the file you need to write server side code. Or you can use ActiveXObject in jquery. eg:

    $(#saveData").click(function(){
    customer.name = $("[id*=comment]").val();
                customer.scramble = $("[id*=DropDownList2]").val();
                customer.confirm = $("[id*=DropDownList1]").val();
       writeToFile(customer.scramble,  customer.confirm,);  
   });
    function writeToFile(scramble, confirm){
        var fso = new ActiveXObject("Scripting.FileSystemObject");
        var fh = fso.OpenTextFile("D:\Scramble.txt", 8, false, 0);
        fh.WriteLine(scramble+ ',' + confirm);
        fh.Close();
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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