I understand a bit because of this post: JQuery, setTimeout not working why it's not working, but keeping everything this way, what is the right way to call _finalvalidate()
inside my div?
<script type="text/javascript">
$(document).ready(function(){
//On Submitting
function _finalvalidate(){
alert('ppp');
if(validateName() & validateEmail() & validatePhone()){
alert('OK');
return true
}
else{
alert('false');
return false;
}
}
});
</script>
<div onclick="_finalvalidate();"> Take action </div>
The jQuery way of doing it would be something like:
<script type="text/javascript">
$(document).ready(function(){
//When clicking on the div, execute this
$("#validation").click(function() {
alert('ppp');
if(validateName() & validateEmail() & validatePhone()){
alert('OK');
return true
}
else{
alert('false');
return false;
}
});
});
</script>
....
<div id="validate"> Take action </div>
If you really want to use the javascript function style, you gonna have to put the function outside the document.ready()
function and then you'll be able to call it with the onclick
attribute:
<script type="text/javascript">
function _finalvalidate(){
alert('ppp');
if(validateName() & validateEmail() & validatePhone()){
alert('OK');
return true;
}
else{
alert('false');
return false;
}
}
</script>
....
<div onclick="_finalvalidate();"> Take action </div>
In this case you don't have anymore jQuery involved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With