Solved

Help with javascript / Jquery

Posted on 2013-10-22
5
319 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 …
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
The viewer will learn how to dynamically set the form action using jQuery.
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now