Solved

Help with javascript / Jquery

Posted on 2013-10-22
5
332 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

749 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