-1

I really thought at first that my code is not working.. but then i tried to create a very simple click event in a clean page and my jquery works on .html but when i open the .php on my XAMPP server it does nothing when it's clicked but it alerts the first one.

index.php

<html>

<head>

    <script src="js/jquery-3.2.0.min.js"></script>

</head>
<body>

<?php include "includes/widgets/login.php"; ?>

</body>
</html>

login.php

<script type="text/javascript">
$(document).ready(function() {
    alert("Something");
    t = clicked();
    $('#login').click(function() {
        alert("Login Alert!");
    });
    function clicked() {
        alert("I was clicked!");
    }
});
</script>

<input type="button" value="Login" id="login" onclick="clicked()">
8
  • Paste your login.php code also Commented Apr 6, 2017 at 4:26
  • edited it now. sorry for the delay. Commented Apr 6, 2017 at 4:26
  • @Siege21x it seems you added php page into html page? if it is it will not wotk Commented Apr 6, 2017 at 4:27
  • the onclick event is also not working but when i declared it on a variable it is working Commented Apr 6, 2017 at 4:27
  • @AlivetoDie, But it alert the message, atleast alert will work. siege21x, please check the browser console ( in developer tools ) for any error. Commented Apr 6, 2017 at 4:27

3 Answers 3

1

place the function clicked(); outside from the document.ready();

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your response brother! But it seems to be the problem is with my computer :D i tried to send a message at console when i click the button and it reaches the log but it just doesnt want to show the message box. Thank you very much for the effort!
0

Change login code to following and it will work.

<script type="text/javascript">
$(document).ready(function() {
    alert("Something");

    t = clicked();
    $('#login').click(function() {
        alert("Login Alert!");
    });
});
function clicked() {
    alert("I was clicked!");
}
</script>

<input type="button" value="Login" id="login" onclick="clicked()">

Uncaught ReferenceError: clicked is not defined at HTMLInputElement.onclick (index.php:22)

This problem will also solved. I don't know properly but i thought that browser can't find function inside jquery.

JQuery create function when DOM is ready.But Control onclick property was read by browser while creating a page but they can't find the function becuse it was not ready yet

So I think procedure may be like :

1) Browser read the page and find the function.

2) JQuery ready event will fire.

Comments

0

Place your function like this:

<script type="text/javascript">
$(document).ready(function() {
alert("Something");
t = clicked();
$('#login').click(function() {
    alert("Login Alert!");
});

});
 function clicked() {
    alert("I was clicked!");
}
</script>

1 Comment

Thank you for your response brother! But it seems to be the problem is with my computer :D i tried to send a message at console when i click the button and it reaches the log but it just doesnt want to show the message box. Thank you very much for the effort!

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.