0

I have the following code:

<script type="text/javascript">
$(document).ready(function AjaxPost() {
 alert('asd');
});
</script>

<body>
<input name="btnUpdateUser" value="Update" id="btnUpdateUser" type="button" onclick="AjaxPost()" />
</body>

My problem it is not working. See live sample here: CodePen

But when I changed the onclick to this:

<input name="btnUpdateUser" value="Update" id="btnUpdateUser" type="button" onclick="javascript:alert('asd');" />

It is showing the alert. What did I missed here? Thanks!

1
  • I suppose AjaxPost doesn't exist. Try var AjaxPost = function() { ... }; $(document).ready(AjaxPost); Commented Aug 30, 2013 at 9:48

2 Answers 2

7

it is because AjaxPost is not present in the global scope.

there is no need to use document ready in this case since the method is invoked by the user

<script type="text/javascript">
function AjaxPost() {
    alert('asd');
}
</script>
Sign up to request clarification or add additional context in comments.

Comments

0

Try this : call this function outside of document

function AjaxPost() {
   alert('asd');
}

Comments

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.