Solved

Help with javascript / Jquery

Posted on 2013-10-22
5
329 Views
Last Modified: 2013-10-30
I have the function below to show a dialog to add items.
THe second time the dialog remember the last thing I entered.
How can I clear the input fillds in it?


$("#create-item")
                .button()
                .click(function () {
                    $("#dialog-form").dialog({
                        autoOpen: false,
                        title: "New Item",
                        height: 325,
                        width: 450,
                        modal: true,
                        buttons: {
                            "Create Item": function () {
                                add_item();
                                $(this).dialog("destroy");
                            },
                            Cancel: function () {
                                $(this).dialog("destroy");
                            }
                        },
                        close: function () {
                            allFields.val("").removeClass("ui-state-error");
                        }
                    });
                   


                    $("#dialog-form").dialog("open");
                    return false;
                });





function add_item() {
            var id = $('#<%=tbId.ClientID%>').val()
            var item = $('#<%=tbItem.ClientID%>').val();
            var descr = $('#<%=tbDescr.ClientID%>').val();
            var qty = $('#<%=tbQty.ClientID%>').val();
            var list_price = $('#<%=tbList.ClientID%>').val();
            var price = $('#<%=tbNet.ClientID%>').val();

            var data = JSON.stringify({ item: item, descr: descr, id: id, qty: qty, list_price: list_price, price: price });
            $.ajax({
                type: "POST",
                url: "HoHo.aspx/AddItem",
                data: data,
                contentType: "application/json; charset=utf-8",
                datatype: "json",
                success: function () {
                    __doPostBack('UpdatePanel1', '');

                    alert("Item added succesfully");
                },
                error: function () { alert("Item wasn't added"); }
            });
0
Comment
Question by:pucko73
5 Comments
 
LVL 15

Expert Comment

by:Ess Kay
ID: 39592437
to reset a form:

var form = document.getElementById("myForm");
form.reset();



Or You can clear out their values by just setting value to an empty string:

var1.value = '';
var2.value = '';
0
 

Author Comment

by:pucko73
ID: 39592449
where do I put that to have it cleared when the dialog is closed?
0
 
LVL 58

Expert Comment

by:Gary
ID: 39592453
Is this in Firefox or all browsers?
0
 

Author Comment

by:pucko73
ID: 39592465
Internet explorer are I'm using. But I would prefere all if possible
0
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 500 total points
ID: 39592942
You clear the fields in the close function:

close: function () {
    allFields.val("").removeClass("ui-state-error");
    //reset your form here
    $('#yourFormID')[0].reset();
}

Open in new window

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question