Jump to content
Larry Ullman's Book Forums

amackley

Members
  • Posts

    2
  • Joined

  • Last visited

amackley's Achievements

Newbie

Newbie (1/14)

1

Reputation

  1. Actually. I found my answer. I had read Chapter 2, but it didn't stick. I carefully read again and now it more clear. Just for reference for anyone else just beginning, and to lock it in my own brain, here are the simplified steps, based on the html and script in CH2. HTML page. At bottom <script src="js/login.js"></script>. This executes the login.js script. At bottom of login.js is --> window.onload = init; This tells us which function to execute when it loads the script. in function init()--> We create a listener var loginForm = document.getElementById('loginForm'); loginForm.onsubmit = validateForm; The validateForm() function does the validate form which returns true if everything is good, if not, it returns false. If the script returns true, then <form action="login.php" method="post" id="loginForm"> actually executes. A key piece of information that I picked up from page 45 is this To start, note that the only thing different about this form and one that wouldn't be tied to JavaScript is that each element has both a name attribute and an id attribute. The name value will be used when the form data is submitted to the server-side PHP script. The id value will be used by the JavaScript. I also learned an understood that JavaScript is an event language. So an event listener will happen before the call to action="somescript.php".
  2. I guess I don't understand the relationship between the php and the javascript. This has plagued my mind how this works. In the very first example, the form uses this line: <form action="login.php" method="post" id="loginForm"> But, below the form is the line: <script src="js/login.js"></script> I understand that because the script is at the bottom of the html page, it is automatically loaded and the init() function is called. What is confusing is, if the form action="login.php", what action actually calls the validateForm() in the javascript? Please help me get beyond this simple but confusing (to me) flow.
×
×
  • Create New...