Click here to Skip to main content
15,664,619 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys

I'm quite new to the world of Javascript and jQuery, so I'm hoping this is a simple fix...

I have an MVC app. In this app I have a partial view that gets populated when a selection is made in a table above it.

The user needs to be able to add a note to a record, so there is a button that opens a jQuery dialog box.

HTML
<div id="dialog-notes" style="display:none;" title="Additional Notes">
     @Html.TextAreaFor(x => x.AdditionalNotes, new { id = "txtNotes" })
     @Html.HiddenFor(x => x.AdditionalNotes)
</div>


When the user enters some text and clicks OK, an action is called to save the info.

JavaScript
<script>
function dialog(dialogBox) {
                $(dialogBox).dialog({
                    modal: true,
                    buttons: {
                        Ok: function () {
                            $(this).dialog("close");
                        }
                    }
                });
            };

            function dialog_notes() {
                $('#dialog-notes').dialog({
                    modal: true,
                    buttons: {
                        Ok: function () {
                            var message = $('#txtNotes').val();
                            var jobID = $('#JobID').val();

                            $.ajax({
                                type: "POST",
                                url: "/Agents/SaveAditionalNotes",
                                data: { jobID: jobID, notes: message },
                                success: function (result) {
                                    dialog('#dialog-notesSaved');
                                },
                                error: function (req, status, error) {
                                    dialog('#dialog-notesSavedFailed');
                                }
                            });
                            $(this).dialog("close");

                        }
                    }
                });
            };
</script> 


Action code for fun:
C#
public ActionResult SaveAditionalNotes(int jobID, string notes)
       {
           Listings list = new Listings();

           return Json(list.SaveAdditionalNotes(jobID, notes));
       }


Now, this works fine first time round. However, if I make another selection in the grid, open up the modal dialog again, type something new and click OK, the result from the textbox of the first time is sent???

Example: First time the value is "Sausages". Second time I type the value "Mashed Potato". The value "Sausages" will be sent instead of "Mashed Potato"...

This has be very confused... Is this normal behavior? How do I stop this?

Thank you in advance.
Posted
Updated 2-Sep-13 12:26pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900