Jump to content

Ingolme

Moderator
  • Posts

    14,901
  • Joined

  • Last visited

  • Days Won

    177

Everything posted by Ingolme

  1. There's a page for it right on the PHP tutorial, which you should read. http://www.w3schools.com/php/php_install.asp Currently I use XAMPP on my computer for testing PHP: https://sourceforge.net/projects/xampp/
  2. So that people can't view the source code and cheat.
  3. In Javascript random numbers are generated with Math.random(), in PHP there is rand, mt_rand and random_int.
  4. Are you sure you're talking about XML? Forms are HTML and the data they send is processed on the server-side by a scripting language such as PHP.
  5. You have to install a server on your local computer in order to run PHP code.
  6. You have not described the problem. What is "right"?
  7. The nodeValue property will not allow you to put HTML into the page, only text, so you would actually have to modify the innerHTML property of the parent of the text node or split the text node into two and put an element node between them. This adds complications because text nodes may be next to element nodes, changing the innerHTML modifies the structure of the DOM. Both innerHTML and adding element nodes will affect the DOM and interfere with your tree traversal algorithm.
  8. You don't have a meta viewport tag on this page.
  9. You would need to do a tree traversal on the DOM, starting at document.body and using the childNodes and parentNode properties to move down and up the tree. For each node, check the node type, if it's an element node, begin traversing its children, if it's a text node then split its nodeValue property into an array of words and loop through them checking to see if any of them exist as a property of the window object. If the property is found then call your function and assign its return value to the specified element in the array. Once done looping through the array join it back together and assign it back to the nodeValue property. To check whether a property exists on the window a single if() statement will work: var word = "something"; if(window[word]) { console.log("Property " + word + " exists in the global scope."); }
  10. Any videogame is going to require a whole lot of research and effort. Yes, I have the knowledge to build a 2D shooter in Javascript, but it's not something short enough to write in a forum post. Javascript is also capable of making 3D games with the new WebGL API. Pretty much nothing is out of Javascript's reach. Python, just like Javascript, is an interpreted programming language, though it is more efficient than scripts running on a browser. Real 3D games are mostly built on compiled languages.
  11. I don't believe the W3C or W3Schools has templates. The site you're getting the template from is not affiliated to the W3C or W3Schools.
  12. <a class="navbar-brand hidden-sm hidden-xs" href="http://www.ibm.com/us-en/" target="blank">
  13. Since you're using Bootstrap, just add the class .hidden-sm and .hidden-xs to the element you want to hide. http://getbootstrap.com/css/#responsive-utilities
  14. You were given a detailed explanation of what needed to be fixed in your code. What part did you not understand?
  15. GET and POST on their own will not allow data to persist between pages, they are just used to send data from the client to the server.
  16. I'd start off by simplifying the HTML: <a id="play-button"><img class="hover2" src="images/play_transparent.png" alt="Play/Pause"></a> Leave all the event handling to Javascript. I don't know where the variable vvid is set, but if you're depending on it to exist without having declared it yourself (for example, "vvid" is the id attirbute of an element) then your code is not likely to work in all environments. If vvid is just an attribute, then set it in the code: var vvid = document.getElementById("vvid"); I don't know what all these functions do so I'll have to leave them as is but I'm pretty sure this code could be optimized further. speed2 setInterv findWord clearInterv So here's the code rewritten to change the image when the video is started or stopped: var button = document.getElementById("play-button"); var img = button.getElementsByTagName("img")[0]; var wordElement = document.getElementById("findWord"); button.addEventListener("click", playPause, false); function playPause() { // Assuming vvid was set somewhere else in the code. if (vvid.paused) { // Unknown code vvid.play(); speed2(1.00); setInterv(); findWord(wordElement.value); // Change the image img.src = 'images/play_transparent.png'; } else { // Unknown code vvid.pause(); clearInterv(); // Change the image img.src = 'images/pause_transparent.png'; } }
  17. If every row only has one cell then what exactly is the purpose of the table?
  18. I haven't included any AJAX in my previous post, but I will edit it to add comments explaining more clearly what I'm doing. Here's how AJAX works: // Create XMLHttpRequest object which the browser uses to make requests to the server var request = new XMLHttpRequest(); // Prepare the connection // 1. "GET" refers to the HTTP request type. // In HTTP, GET is used when we want get information from the server // POST would be used if we wanted to send information to the server // 2. "desktop.php" is the path to the file we want to read. // 3. "true" refers to asynchronous requests, this should always be true. // If set to false the browser will freese until the request has completed. request.open("GET", "desktop.php", true); // The onreadystatechange property is an event listener, it gets called automatically while the request occurs request.onreadystatechange = handleResponse; // Send the request request.send(); // This function is called when the ready state of the request changes. // Ready state 4 means data has been returned from the request. // An HTTP status code of "200" means that the request was successful. function handleResponse() { if(request.readyState === 4 && request.status === 200) { // request.responseText contains the contents of the file we requested from the server. // console.log() shows information in the browser's Javascript console which you can access by pressing F12 in most browsers console.log(request.responseText); }; }; In short, we can condense all that into this useful little function: // Requests data to the server and runs the function "callback" sending the data to it // We could make it more fancy by handling errors, but this is just a simple function function requestData(url, callback) { var request = new XMLHttpRequest(); request.onreadystatechange = function() { if(request.readyState === 4 && request.status === 200) { callback(request.responseText); } } } Here's how to use the function we just created: requestData("desktop.php", showOnPage); function showOnPage(data) { document.getElementById("content").innerHTML = data; } You can use it in the previous code like this: if(switchToDesktop) { requestData("header.desktop.html", updateContent); } else if(switchToTablet) { requestData("header.tablet.html", updateContent); } else if(switchToMobile) { requestData("header.mobile.html", updateContent); } /* This goes outside of everything else */ function updateContent(data) { // Assuming you have <div id="content"></div> on your page // wherever you want the content to appear document.getElementById("content").innerHTML = data; }
  19. Or more efficiently: /* Place code right before the closing </body> tag */ // Reference to elements var button1 = document.getElementById("btn1"); var button2 = document.getElementById("btn2"); var list = document.getElementById("List"); var option = list.querySelector("option[value=A2]"); // Event listeners button1.addEventListener("click", changeOption, false); button2.addEventListener("click", changeOption, false); // Change option text function changeOption(e) { var text; // Select text based on which button was clicked if(e.target == button1) { text = "Plane"; } else { text = "Bike"; } // Change the text option.text = text; }
  20. I think if you set a max-height on the dropdown element it will have have a scrollbar.
  21. Ingolme

    Mobile

    You'll have to learn the principles of responsive design. I'm pretty sure a simple search for "responsive design tutorial" will help.
  22. The reason your code is constantly redirecting is because assigning to window.location forces a redirect. In summary, this is what I understood: You want to display different content for different screen sizes. There are many way to do this. I believe the easiest solution is actually to use media queries to set the content you don't need to "display: none". If you're opposed to that, you can have Javascript detect the screen size and load different content. You should read the AJAX tutorial to learn to do AJAX requests. // onload and onresize are events on the window object // The functions assigned to them get called when the window first loads and when it is resized, respectively. window.onload = changeContent; window.onresize = changeContent; // I'm storing useful numbers inside "constants" // (Javascript doesn't have real constants, so uppercase variable names will do) var MOBILE = 767; var TABLET = 1024 function changeContent() { // We compare the window's width to the width it had before so that we only // do something if we're changing views, not just every time the screen is // resized. if(!window.previousWidth) { // Use -1 for the previous width if we've never assigned anything to it before window.previousWidth = -1; } // Shorten the variable names to make the code more readable var pw = window.previousWidth; var w = window.innerWidth; // window.innerWidth is provided to us by the browser telling us the width of the page // It's considered switching to desktop if the current width is larger than // tablet size and the previous width was equal to or smaller than a tablet size var switchToDesktop = w > TABLET && pw <= TABLET; // It's considered switching to tablet if the current width is larger than a // mobile screen but smaller or equal to a tablet screen and the previous width // was either mobile size or larger than desktop size. var switchToTablet = w > MOBILE && w <= TABLET && (pw <= MOBILE || pw > TABLET); // We consider that it's switching to mobile when the current width is the size of // a mobile screen and the previous width was larger than a mobile screen or was // not set. var switchToMobile = w <= MOBILE && (pw > MOBILE || pw == -1); // The window's current width will be the previous width next time this function is called window.previousWidth = window.innerWidth; if(switchToDesktop) { // Load desktop.php page with AJAX } else if(switchToTablet) { // Load tablet.php with AJAX } else if(switchToMobile) { // Load mobile.php with AJAX } } When you load the content with AJAX you need to put it into an element, you could do that with document.body.innerHTML = [data from response] The files you're loading with AJAX should only be what goes between the <body> tags and not include <html> or <head> tags.
  23. This alone will work, the outer loop is completely unnecessary. $sql = "SELECT * FROM `tracker` ORDER BY movement ASC"; $qry= mysql_query($sql); while ($row= mysql_fetch_array($qry)) { $code= $row['code']; $current= $row['25']; $up= $row['ups']; $down= $row['downs']; $evens= $row['evens']; $movement= $row['movement']; $bigup= $row['bigup']; $bigdown= $row['bigdown']; $upcount= $row['upcount']; $downcount= $row['downcount']; $twentyfive= $row['25']; $twentyfour= $row['24']; $commission= 15; // Display information here } I would recommend not using the MySQL library, it is deprecated because it is insecure. Use PDO or MySQLi
  24. Browsers automatically add that if the browser calls alert() more than once.
×
×
  • Create New...