0

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?

Ɖiamond ǤeezeƦ
  • 3,223
  • 3
  • 28
  • 40
kiran
  • 153
  • 1
  • 3
  • 15

2 Answers2

0

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

Saveasfile

and are trying to get

saveasfile

overburn
  • 1,194
  • 9
  • 27
-1

.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();
    }
Mohammad Imran
  • 125
  • 1
  • 6