2
I have a system with several forms calling jQuery and ajax to solve the problems and register the recovered data in mysql database. As a beginner, I am having problems due to lack of knowledge. What I learned:
<script src="jQuery"></script>
<script>
$(document).ready(function(){
$("#enviar").click(function() {
$nome = $("nome").val();
if(nome != "") { tratamento e banco } else { avisa o usuário }
});
});
</script>
<body>
<form action="" method="post" enctype="application/x-www-form-urlencoded">
<input type="text" id="nome">
<input type="submit" id="enviar">
</form>
But now I have to process 20 variables, suddenly make functions to validate some and then with ajax send to the database and process all messages. I can’t write this script any other way than in an external . js that will stay just for that. I tried to create one . js external but when I click send the script does not search the . js with the parameter #enviar
to begin processing the form even if form action
I call the file PHP
and put jQuery inside it.
Question: How to give id action enviar
in form Submit, it will fetch the external file and will process all this javascript. I am a beginner but I already have systems in PHP. Now, how do I call my external javascript?
I also tried to insert it at the top of the system thinking it would be a include
or require
as in the PHP
but totally unsuccessful.
If it works, and of course it will, you’re a super-cool guy, and I’ll give you the best answer. Everyone here could be so understanding with beginners. You mean that calling my file under the form will run . js before . php? Outstanding.
– Marcos Vinicius
Excellent @Daniel Neis ... thank you so much for your help. Excellent your answer which is the solution of my question. I expect thousands of nice people like you around.
– Marcos Vinicius
With this experience I also discovered a little of the reason why the scripts go to the bottom of the sites, precisely to make this call before PHP among other things. Infos for beginners like me.
– Marcos Vinicius