Solved

Help with javascript / Jquery

Posted on 2013-10-22
5
318 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
Comment Utility
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
Comment Utility
where do I put that to have it cleared when the dialog is closed?
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
Is this in Firefox or all browsers?
0
 

Author Comment

by:pucko73
Comment Utility
Internet explorer are I'm using. But I would prefere all if possible
0
 
LVL 42

Accepted Solution

by:
Chris Stanyon earned 500 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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…

771 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