0

When i'm tryng to click the button i'm ghetting an error : popup is not defined , i have no ideea what to do

<input href="#dialog" type='button' value='Open' onclick="popup(<?php echo $image['image_id']; ?>); return false;" />

<script type="text/javascript">
    function popup(image_id){
                $.ajax({
                    cache: false,
                    type: 'POST',
                    url: 'popup.php',
                    data: 'image_id=' + encodeURIComponent(image_id),
                    success: function(data) { 
                        }
                });
            }
</script>
7
  • 1
    Duplicate: stackoverflow.com/questions/8978944/jquery-variable-not-defined Commented Jan 23, 2012 at 21:38
  • What's the image id? If it's a string you need to wrap it in quotes, but other than that it's fine. I just ran it and got no errors, so there must be something else causing the problem. Commented Jan 23, 2012 at 21:39
  • Pff think is coze of my internet lagging // Duplicate deleted Commented Jan 23, 2012 at 21:41
  • image_id is an php id from database Commented Jan 23, 2012 at 21:42
  • Please post how your final rendered HTML page looks like. Commented Jan 23, 2012 at 21:48

1 Answer 1

1

Are you using href attribute of this input element? If not then you don't need that. Also I would suggest you to attach the click handler using jQuery. But if your markup and server side code does not help then you can try this.

<script type="text/javascript">
            function popup(image_id){
                $.ajax({
                    cache: false,
                    type: 'POST',
                    url: 'popup.php',
                    data: 'image_id=' + encodeURIComponent(image_id),
                    success: function(data) { 
                        }
                });
                return false;
            }
</script>

<input href="#dialog" type='button' value='Open' onclick="return popup('<?php echo $image['image_id']; ?>');" />
Sign up to request clarification or add additional context in comments.

11 Comments

And yes i'm using the href atribute to open a popup and return the result of ajax in the popup
Did you try my edited answer? Try putting the script before the markup.
Yes same error, i tryed adding click function and document rdy function but same thing
Yes just the same order as in my main post
You must be having js error on the page because of which popup function is not parsed by JS engine. Take a look in the console if you see any errors.
|

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.