Jump to content

Ingolme

Moderator
  • Posts

    14,901
  • Joined

  • Last visited

  • Days Won

    177

Everything posted by Ingolme

  1. window is the root object, the global scope. Any time you declare a variable in the global scope it becomes a property of the window. Properties can be accessed either by dot notation ( window.alert ) or by square brackets ( window["alert"] ). The advantage of square brackets is that you can use variables as property names: var f = "alert"; console.log( window[f] );
  2. I forgot the delimiters, but [ ] are not delimiters, they are part of the regular expression. If you don't know regular expressions, here's a place you can learn about them: http://www.regular-expressions.info/
  3. I would favor an approach that works without Javascript, with a layer of Javascript added on top for user convenience.
  4. Please try to make your contributions to the forum meaningful.
  5. IDs have to be unique, you can't have three elements with the same ID. The ID is supposed to identify a single element on the page. If you want to reference multiple elements use the class attribute. <div class="img"> <img class="image" src="aithousa_anamonis_1.jpg" alt="Αίθουσα αναμονής 1" width="300" height="200"> </div> <div class="img"> <img class="image" src="aithousa_anamonis_2.jpg" alt="Αίθουσα αναμονής 2" width="300" height="200"> </div> <div class="img"> <img class="image" src="aithousa_anamonis_3.jpg" alt="Αίθουσα αναμονής 3" width="300" height="200"> </div> Now you loop through all the elements with the given class name and add the event listeners. var images = document.getElementsByClassName("image"); for(var i = 0; i < images.length; i++) { images[i].onclick = showCaption; } function showCaption(){ modal.style.display = "block"; modalImg.src = this.src; captionText.innerHTML = this.alt; }
  6. You don't need the SELECT statements in there, just use the expressions. You have way too many parentheses in your code. This will probably work: CONCAT( CAST( CHAR( floor( 65 + rand() * (1+90-65) ) ) AS CHAR(3) ) , '%')
  7. Here's the mail tutorial from W3Schools: http://www.w3schools.com/php/func_mail_mail.asp It uses PHP's mail() function.
  8. That's not actually validation, that's sanitation. Validation would be if you told the user that the name they posted is invalid (which would probably be a better idea, since they might not like the outcome of the replacement your code is making). Your current preg_replace() call will actually replace an entire valid string with nothing. Here's how you would remove unwanted characters: $name = preg_replace('[^a-zA-Z]', '', $name); This code removes anything that's not a letter.
  9. Yes, PHP include treats the code as if it was pasted right there, it's in the same scope.
  10. I call a file a "template" if it's mostly plain HTML with some variables, loops and conditions just for the sake of displaying data. A template file should not do any data processing, it's just there to display the data. In one file you have all your PHP doing all the logic. After all the logic is done, data is assigned to variables that are made available to the HTML template: Here's an example: Logic: $comics = array( array( 'name' => 'Comic 1', 'image' => '/images/comic1.png' ), array( 'name' => 'Comic 2', 'image' => '/images/comic2.png' ) ); include 'template.php'; template.php: <h1>List of Comics</h1> <?php foreach($comics as $comic) { ?> <div class="comic"> <h2><?php echo $comic['name']; ?></h2> <img src="<?php echo $comic['image']; ?>" alt="<?php echo $comic['name']; ?>"> </div> <?php } ?>
  11. You probably should attach the actual file you're using.
  12. I'm not sure what you expected it to do. You can't animate background images, you can only animate properties with numbers as values. (colors are also numbers) Here's a list of properties that can be animated: http://www.w3schools.com/cssref/css_animatable.asp jQuery is capable of animating a few Javascript properties which aren't on that list, such as scrollTop.
  13. The model's permanent data storage is the database. From the point of view of objects interacting with the model, the model always has the data readily available, but internally it's pulling from the database. In my usual implementation the controller takes data from the model and sends it to the view, the model usually never interacts directly with the view. The controller also gives data from the user to the model to be stored. The model takes care of storing information into the database and pulling it out of the database and converting it into a usable format.
  14. It's possible to create variable length templates with the right data structures, you just need to put a loop in your HTML template. When you load a page you load all the information from the database and generate the necessary data structures. Every time a page is loaded a new PHP process is started, so the data from the previous page is not there anymore and has to be loaded again.
  15. It works for me. It won't work if you run that script in the <head> section because the body has not loaded yet. I would recommend using console.log() rather than document.write().
  16. Flexbox won't work in most versions of Internet Explorer in use today.
  17. You would do best with a server-side language like PHP. PHP can load data from other sources and put it into HTML.
  18. It's clear PDO's MySQL extension is active and enabled because it's attempting to connect to the MySQL server. Perhaps you should install a server package like XAMPP on your computer for testing, it takes care of setting up the server properly for you. Installing Apache, MySQL and PHP separately is more prone to human error.
  19. Your PHP code is correct. The issue most likely has something to do with your server setup. I don't know your MySQL server's username, password or port number (and it wouldn't be smart to post the user and password on a public forum), but the issue could be that one of those is wrong.
  20. Maybe the port number is wrong, or you haven't started up the MySQL process on your local server.
  21. Yes, that's pretty much what I said. The "javascript:" prefix is not required in the onclick attribute.
  22. It would do the same thing. However, in this case previousSibling would reference a text node with a node value of "Some text" <html> <head> <title>DOM Tutorial</title> </head> <body> <h1>DOM Lesson one</h1> Some text <p>Hello world!</p> </body> </html>
  23. If oNode is the first child, that means it has index 0, the function would try to return an element with index [0 - 1]. There's nothing in the list at index -1, so it would throw an error. The result of this function is different from previousSibling, because the node is always an element node. The previousSibling property may point to a text node or a comment node.
×
×
  • Create New...