1

I am using Spring MVC and i would like when i insert a record into the database via a POST when the user is returned to the view i would like to show something like a Jquery dialog to the user that says the transaction was successful/display an error message to the use in the dialog.

I implemented the Jquery dialog but for some reason its not working the way i would like it to. I have created it like this :

jquery

 function ShowDialog() {
            $( "#dialog" ).dialog({
                modal: true,
                buttons: {
                    Ok: function() {
                        $( this ).dialog( "close" );
                    }
                }
            });
        }

I attached this to an element event when change:

$('#results').change(function()){

            if($('#results').val().length != 0){

                ShowDialog();


            }


        }    

However when the form loads i get a blank dialog popping up. The element 'results' is empty and gets set form the server using model.addAttribute("results","Record Was Updated") and where the i created named 'dialog' is located i can see the dialog icon being displayed.

html

<div id="dialog" title="Server Response">
            <p>
                <span class="ui-icon ui-icon-info" style="float: left; margin: 0 7px 50px 0;"></span>
                <label id="results">${results}</label>
            </p>

</div>

1 Answer 1

3

In your change event change the second line to this:

if($('#results').html().length != 0){

The .val() only works for form elements (input, select and textarea), whereas #results is a normal html element.

Sign up to request clarification or add additional context in comments.

2 Comments

I made that change however i am seeing the dialog icon showing in the page and there isn't any dialog being displayed any suggestions?
ok i made another change however i am seeing the dialog icon showing in the page where i typed the dialog div after the dialog is displayed the icon doesn't show again any suggestions?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.