tags:

views:

58

answers:

4

I've got a .js file that has this function in it:

function showDialog(divID) 
{
    alert("got here");

    var dialogDiv = $(divID);

    dialogDiv.dialog
    (
        {
            bgiframe: true,
            modal: true,
            autoOpen: false,
            show: 'blind'
        }
    )

    dialogDiv.dialog("open");
}

And in my page this:

<script type="text/javascript">

    $(function()
    {
        $("input.invokeDialog").click.showDialog("#testDialog");
    });

</script>

I'm trying to figure out why it doesn't recognize my showDialog function. Is it not possible to reference it with the dot as I am doing? Do I need a jQuery specific function or syntax for it to know that it's a jQuery function or is there no such thing?

A: 

how are you including the .js file with the function in it?

Jay
from code-behind, this is ASP.NET. Same way I include the jQuery framework which is working and recognizing any jQuery syntax.
CoffeeAddict
+1  A: 

Try this:

  $(function()
    {
        $("input.invokeDialog").click(function(){
           showDialog("#testDialog");
        });
    });
Sarfraz
did not work...but thanks.
CoffeeAddict
I get the error ": expected" for showDialog in Visual Studio in ASP.NET when working in the mark-up.
CoffeeAddict
That should work perfectly. Could you please tell us what did not work? Is it not showing the dialog? And could you post the whole showDialog function. It got cut off.
Raja
When I click the button, nothing is happening even if I put an alert in the showDialog function.
CoffeeAddict
If you put an alert right above the showDialog call in the code above, does that show up?
Wesley Petrowski
no, not doing a damn thing.
CoffeeAddict
Does your input element have class="invokeDialog" in it?
Wesley Petrowski
It's input: not input.
CoffeeAddict
+2  A: 

The problem with click.showDialog("#testDialog") is that it means you are trying to call a function called showDialog which is part of the click object. You have defined the showDialog function as a free-floating function, so you don't need anything in front of it to call it.

The code in Sarfraz's answer should work well for what you're trying to do.

Wesley Petrowski
so how would you recommend calling free-floating functions outside of Sarfaz's suggestion ?
CoffeeAddict
A: 
<script type="text/javascript">

    $(function()
    {
        showDialog("#testDialog");
    });

</script>

What about this?

drachenstern
that's not tied to any DOM element..it will never be called.
CoffeeAddict
Yeah I meant to hook it to document onload... after reading a few other comments I decided that you're probably not gonna even try that one. So just left it to see what commentary you did add.
drachenstern
I think drachenstern is trying to narrow down whether the problem is occurring in the binding of the click event, or in the calling of the showDialog function itself.The $ in this case is a synonym for $(document).ready(). It will be called as soon as the document is finished loading. The code in your question uses the same syntax. :)
Wesley Petrowski