Jump to content

spence911

Members
  • Posts

    38
  • Joined

  • Last visited

About spence911

  • Birthday 09/24/1997

Profile Information

  • Gender
    Male

spence911's Achievements

Member

Member (2/5)

0

Reputation

  1. I can't find an explicit answer on this anywhere, but when you create a child class from an abstract class must you use ALL of the methods that are inside the abstract class in the new child class? Or are these methods just available to the child class to pick and choose?
  2. Just figured this out. Its a constant that ensures that the data returned is an integer(TINYINT, MEDIUMINT, BIGINT...) so that PDO can pass the correct data type to MySQL. PDO will also escape any quotes and other characters thereby preventing SQL injection.
  3. What's up guys! Can somebody please explain the meaning of PDO::PARAM_INT in the following statement: $pdoStmt->bindValue(":num", $num, PDO::PARAM_INT); I have already created a PDO Statement object called $pdoStmt. This line will bind the value of $num to the placeholder called :num. I know that PDO::PARAM_INT is a Predefined Constant but what does it do in this case? Thanx
  4. Thanks for the workaround. So if I understand correctly, the value of links is undefined because once the for loop has finished executing, whatever new value the for loop has created for var links is thrown out and replaced by the original value which is var links = document.links; correct?
  5. Whats up guys. I've created two links in an html document. The problem is the JavaScript below gives me a value of undefined after running the for loop. I know this has something to do with closures, which I don't have much experience with so I can't figure out why the value of links is undefined. JavaScript: window.onload = function getLinks(){ var links = document.links; for(var i = 0, count = links.length; i < count; i++){ links[i].onclick = function(){ alert(links[i].href); return false; }; } }; html: <body> <p><a href="linkOne.html" id="link" target="linkOne">Link B</a></p> <p><a href="linkTwo.html" id="link" target="linkTwo">Link A</a></p> <script src="js/handleLinks.js"></script> </body> </html>
  6. Thanks a lot. That I know. But why does removing the catch block affect the very last line: document.write( "Back to safety." ); That last line will only execute if the catch block is not omitted out.
  7. Hi guys! I would really appreciate it if somebody could explain to me why in the code below the last line "document.write( "Back to safety." );" will only execute if the catch block is not commented out. In other words, the script below will output "Finally!". But if the catch block is not commented out, the output is "Caught your error:someFunction is not definedFinally!Back to safety." <head> <title>Title Time! Yeah</title> <script type="text/javascript"> try { // Throw an error so the catch is triggered. nonExistentFunction(); } /*catch( error ){ // Catch the error. document.write( "Caught your error:", error.message ); } */ finally { document.write( "Finally!" ); } // We got past our try/catch. document.write( "Back to safety." ); </script> </head> <body> </body> </html>
  8. Thanks denno020. I created a <p> container with the id of output and added this at the top of the function: document.getElementById('output').innerHtml = '';. But I'm still getting an error messages on every click instead of just one. html: <body> <div><label for="firstName">First Name</label> <input type="text" name="firstName" id="firstName" value="First Name"/></div> <input type="button" name="btn" id="btn" value="Submit"/> <p id="output"></p> <script src="js/validayt.js"></script> </body> </html> js: window.onload = function(){ 'use strict'; document.getElementById('btn').onclick = function(){ document.getElementById('output').innerHtml = ''; if(document.getElementById('firstName').value == document.getElementById('firstName').defaultValue){ var msg = document.createTextNode('Incorrect information.'); document.getElementById('output').appendChild(msg); } }; };
  9. I'm using JavaScript to validate a form field. Basically, if the form is submitted and the default value of the field is not altered, a text node with an error message will be generated. Problem is if the submit button is clicked over and over, the error message will appear just as many times as the button is clicked, ie. Incorrect information.Incorrect information.Incorrect information.Incorrect information. How do I make the generated message appear only on the first button submit. I tried this but it JavaScript: window.onload = function(){ 'use strict'; var errorMsg = 'Incorrect information.'; document.getElementById('btn').onclick = function(){ if(document.getElementById('btn').value == document.getElementById('btn').defaultValue){ var msg = document.createTextNode(msg); document.getElementById('btn').parentNode.appendChild(msg); /* This if statement didn't work if(msg){ document.getElementById('btn').parentNode.replaceChild(msg); }*/ } }; }; html: <body> <form action="#" method="POST" id="theForm"> <div><input type="text" name="firstName" id="firstName" value="First Name"/></div> <input type="button" name="btn" id="btn" value="Submit Info"/> </form> <script src="js/validate.js"></script> </body> </html>
  10. Since the form's action is login.php, I'm guessing return true; could replace document.getElementById('theForm').submit(); I dont know if I'm right on this one. If it helps, this is what the html looks like: <body> <!-- login.html --> <form action="login.php" method="post" id="loginForm"> <fieldset> <legend>Login</legend> <div><label for="email">Email Address</label><input type="email" name="email" id="email" required></div> <div><label for="password">Password</label><input type="password" name="password" id="password" required></div> <div><label for="submit"></label><input type="submit" value="Login →" id="submit"></div> </fieldset> </form> <script src="login.js"></script> </body>
  11. My bad (noob moment), I just realized that its a precaution for if the AJAX call fails; the form submission will still go through. But would we get the same effect if we used return true; instead of document.getElementById('theForm').submit();
  12. This is a script that validates a user's email and password. Everything is super clear but I can't figure out the purpose of document.getElementById('theForm').submit(); As far as I know, it's a method that submits the form to the script referenced inside the forms html action tag eg. <form action="login.php"> (just in case ajax fails for whatever reason). But I can't find any information to validate this. function validateForm() { 'use strict'; // Get references to the form elements: var email = document.getElementById('email'); var password = document.getElementById('password'); // Validate! if ( (email.value.length > 0) && (password.value.length > 0) ) { // Perform an Ajax request: var ajax = getXMLHttpRequestObject(); ajax.onreadystatechange = function() { if (ajax.readyState == 4) { // Check the status code: if ( (ajax.status >= 200 && ajax.status < 300) || (ajax.status == 304) ) { if (ajax.responseText == 'VALID') { alert('You are now logged in!'); } else { alert('The submitted values do not match those on file!'); } } else { document.getElementById('theForm').submit(); } } }; ajax.open('POST', 'resources/login.php', true); ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); var data = 'email=' + encodeURIComponent(email.value) + '&password=' + encodeURIComponent(password.value); ajax.send(data); return false; } else { alert('Please complete the form!'); return false; } } // End of validateForm() function. // Function called when the window has been loaded. // Function needs to add an event listener to the form. function init() { 'use strict'; // Confirm that document.getElementById() can be used: if (document && document.getElementById) { var loginForm = document.getElementById('loginForm'); loginForm.onsubmit = validateForm; } } // End of init() function. // Assign an event listener to the window's load event: window.onload = init;
  13. Thanks gristoi, if I'm coorect the native (or default behavior) of the first link is to open "popupB.html". This is what the html looks like btw: <body> <p><a href="popupB.html" id="link" target="PopUp">B Link</a> (Will open in a new window.)</p> <p><a href="popupA.html" id="link" target="PopUp">A Link</a> (Will open in a new window.)</p> <script src="js/popups.js"></script> </body> </html> Why do we still need a return false after the function has completed and the popup window is open?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.