Solved

Help with javascript / Jquery

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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…

776 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