Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I know there are many other similar questions on here, but none of them have solved my problem.

I am trying to create a dialog box which prompts the user to choose whether to leave the page (and continue to the link they just clicked) loosing the text they have entered in a textarea, or stay on the page.

Many other answers say to check for repetition of the reference to JQuery, so I have stripped out all references and put in the following at the top of my _Layout.cshtml page.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>

Other answers have also looked at whether the relevant parts of UI were included. I believe the above reference includes everything?

So here is my script, included at the bottom of the relevant page, and the div (I got the div and script from another answer about how to create the dialog). I have included my other scripts in case that is causing a problem.

<div id="dialog" title="Confirmation Required">
  Are you sure about this?
</div>

<script type="text/javascript">    
    $(document).ready(function ()
    { 
        $("#dialog").dialog({
            modal: true,
            bgiframe: true,
            width: 500,
            height: 200,
            autoOpen: false
        });

        $("a.profile").click(function (e) {
            e.preventDefault();
            var hrefAttribute = $(this).attr("href");

            $("#dialog").dialog('option', 'buttons', {
                "Confirm": function () {
                    window.location.href = hrefAttribute;
                },
                "Cancel": function () {
                    $(this).dialog("close");
                }
            });

            $("#dialog").dialog("open");
        });

        $('a.ico').click(function (event) {
            expandTextArea();
        });
        $('textarea#notes').blur(function () {
            expandTextArea();
        });
    });    

    function expandTextArea()
    {
        $("textarea#notes").height($("textarea#notes")[0].scrollHeight);
    }
</script>

I would greatly appreciate it if someone could point out what is wrong, or give me a better solution for creating my confirmation dialog.

Thank you in advance.

Addition:

This is the error I get in the console in Chrome:

Uncaught TypeError: Object [object Object] has no method 'dialog'     person:403
(anonymous function)                                                  person:403
c                                                                     jquery.min.js:4
p.fireWith                                                            jquery.min.js:4
x.extend.ready                                                        jquery.min.js:4
q                                                                     jquery.min.js:4

Person is a partial page in the page index.cshtml that contains the jquery.

@Html.Partial("_Person", Model.Person);
share|improve this question
    
Do you have any cached versions of your script files? In addition, have you checked in the console to ensure that only one copy of each script is being loaded? –  David L Jun 13 '13 at 13:35
    
Hi @DavidL, how would I check to see if the script files are cached, or if only one copy of the script is being loaded? I am currently using Chrome and its Console. Many thanks! –  tekiegirl Jun 13 '13 at 14:31
1  
In chrome, on the network tab, all cached files show up with a status of 304, (not modified). They are not modified because they are already cached. Check all network traffic and make sure you aren't pulling down multiple copies somehow. Also, make sure you aren't getting any 404s on needed scripts –  David L Jun 13 '13 at 14:32
    
It seems it was a problem with one of my other scripts that was bundled. When I removed them the 'has not method dialog' error disappeared. My problem now is that the dialog appears at the bottom of my page, with different dimensions to those I have specified, and all the text is jumbled and outside the white box. I will have to look at all my stylesheets, but I don't think they are the problem. Thank you for your help. –  tekiegirl Jun 13 '13 at 15:19
    
Glad you got it :) –  David L Jun 13 '13 at 15:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.