• Content count

  • Joined

  • Last visited

  • Days Won


Everything posted by davej

  1. Ingolme just discussed this topic in a Php thread. You would use the same Javascript but direct it to your servlet url. AJAX_PHP
  2. As the last item at the bottom of the body add your code or; <script>document.write('<br>'+document.URL);</script>
  3. Yeah, it seems odd that the multi-page requirement isn't listed above, but the OP made it clear that it was also one of the requirements. Several of the bullet items seem rather vague to me. What sort of array of options? What is an "engaging interaction?"
  4. He told us this was a school assignment, so I don't want to simply post a solution. He also told us it must consist of multiple pages with one question per page. His instructor told him to use only HTML, CSS and Javascript. His Javascript code is filled with errors and does not display an understanding of what needs to be done. We told him to look at Local Storage several times.
  5. Okay, if there is only one question per page then why do you need a submit button? The way you had it before you edited it was fine. If you only have one question per page then why does your code need a loop? Your else-if's are wrong and you are confusing = and ==. If indeed you have only one question per page then you simply have the buttons store the answer and then jump to the next page. Only the final page will do any calculations. I guess you can have a submit button if you want it, but that adds complexity because then you would probably want to change the style of the selected button. If you immediately jump to the next page then you don't need to consider styling that button.
  6. So then again I will tell you to go look at... https://www.w3schools.com/html/html5_webstorage.asp If this is a "beginner level" class then the instructor is being silly and unrealistic.
  7. What are the prerequisites for this class? What languages does s/he expect you to use?
  8. Try... <script> 'use strict'; function init() { var buttons = document.getElementsByClassName('btn'); for(var i=0 ; i<buttons.length ; i++){ buttons[i].onclick = clkhandler; } } function clkhandler(evt){ var ans = evt.target.innerHTML; var ques = evt.target.parentNode.getElementsByClassName('text')[0].innerHTML; alert(ques + " = " + ans); } window.onload = init; </script>
  9. It sounds like you are talking about two different things. You could use a JSON string to dynamically create the form or you could read the submitted form and create a JSON string for AJAX, or you could do both. I don't think it would be efficient to use the same JSON structure to do both.
  10. One the server side you have session variables or a database. On the client side you have local storage... https://www.w3schools.com/html/html5_webstorage.asp For a typical quiz you will want to put the scoring and storage of final results on the server side.
  11. Obviously you can post questions here. You might also check MeetUp.com for local developer groups.
  12. I have been playing with something like that. I am thinking that ip addresses and usernames can be added to a timeout table. Each session can also have an "ignore" flag. Each new session gets looked up to see if the username or ip-address is in the timeout table. If it is found in the table then the "ignore" flag is set.
  13. Try experimenting with this and you will see the problem... window.onclick = function(e) { if (!e.target.matches('.dropbtn')) { alert('try to remove show from myDropdown'); var myDropdown = document.getElementById("myDropdown"); if (myDropdown.classList.contains('show')) { myDropdown.classList.remove('show'); } }else{ alert('ignore'); } }
  14. Why do you think your anchor tag needs the same id as something else?
  15. What type of server or what type of hosting are you talking about?
  16. There is always the simple nbsp character, but if you have no understanding of CSS then you should learn how to use that.
  17. The only consideration that the loop introduces is the need for a styling approach that will accept a varying number of these div blocks.
  18. This works in Php, but most programmers use various languages. For example in Javascript this same approach fails... <script> arrtest['letter1'] = 'a'; arrtest['letter2'] = 'b'; alert(arrtest['letter1']); </script>
  19. Initializing variables can prevent a program from crashing unexpectedly. Isn't that a good enough reason? Also Php is very, very forgiving (also known as "idiot-proof"). Why learn bad habits that are poor programming in other languages? Try your code in Javascript and you will see that it fails. In Javascript (and almost all languages) an array must be declared before use.
  20. .form-actions {width:200px; margin-left:auto; margin-right:auto; text-align:center;}
  21. Review available Php security suggestions such as... https://www.owasp.org/index.php/PHP_Security_Cheat_Sheet
  22. Most Javascript experts advise the total avoidance of eval(). In fact classic Javascript has so much baggage that books have been written just to tell you what features you should avoid using. http://archive.oreilly.com/pub/a/javascript/excerpts/javascript-good-parts/bad-parts.html
  23. Is this your code or just some code example that you copied from somewhere? I would suggest that you begin with a simpler example of using local storage. https://www.w3schools.com/html/html5_webstorage.asp
  24. Inheritance in most languages is when you have a Person class and also an Employee class. You can then have Employee inherit Person since every employee is also a person. Classic Javascript has a prototype scheme that is rather strange. You can google "Javascript inheritance" to find various discussions of both the classic Javascript and the new es6/es2015 approaches.