1

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?

asked Apr 13, 2010 at 17:26

3 Answers 3

2

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.

answered Apr 13, 2010 at 17:41
Sign up to request clarification or add additional context in comments.

1 Comment

so how would you recommend calling free-floating functions outside of Sarfaz's suggestion ?
1

Try this:

 $(function()
 {
 $("input.invokeDialog").click(function(){
 showDialog("#testDialog");
 });
 });
answered Apr 13, 2010 at 17:28

5 Comments

I get the error ": expected" for showDialog in Visual Studio in ASP.NET when working in the mark-up.
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.
When I click the button, nothing is happening even if I put an alert in the showDialog function.
If you put an alert right above the showDialog call in the code above, does that show up?
Does your input element have class="invokeDialog" in it?
0
<script type="text/javascript">
 $(function()
 {
 showDialog("#testDialog");
 });
</script>

What about this?

answered Apr 13, 2010 at 17:46

3 Comments

that's not tied to any DOM element..it will never be called.
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.
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. :)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.