Jump to content
Larry Ullman's Book Forums


  • Content Count

  • Joined

  • Last visited

  • Days Won


HartleySan last won the day on March 7

HartleySan had the most liked content!

Community Reputation

826 Excellent

About HartleySan

  • Rank
    Advanced Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. I think so, yes. To me, Larry's books have always been about teaching the fundamentals really well, and then it's up to you to take that knowledge and apply it. I don't think the fundamentals have changed at all since that book came out. Once you get through the book and understand what it's saying, you can very easily go through all the changes in all subsequent PHP versions and pick them up. The changes are nothing revolutionary. Once you get through the book, if you want to then focus on something that's most likely to get you a job / help you start a career, I would learn a modern PHP framework that's still very relevant. Laravel instantly pops to mind as I write that. Good luck!
  2. Disabling a checkbox in JS is actually really easy. You simply do the following: checkboxDomElem.disabled = true; And you can toggle the checkbox back on by setting disabled to false. The trick is writing the correct logic in your JS (or PHP, and then pass it over to your JS) that knows that when you click a particular checkbox in the first row to disable three particular checkboxes in the second row, etc., etc. For that, there are any number of things you can do, but I personally prefer Vue.js these days. It's an extremely powerful JS framework that makes this stuff easy. With it, you essentially just have to pass it a dependency tree, so that it knows which checkboxes are conditionally dependent on which others and you're done. Good luck!
  3. A 404 error is a page-not-found error, which means that your server cannot find the script in question. In other words, the URL to the file is probably incorrect. Within the xampp folder, where is the script stored, and is your Apache server running? Thanks.
  4. kbear, are you using some third-party library or did you build the slide-out yourself? If it's the former, then you'll have to check the documentation for the library, as there's likely an option to prevent it from sliding in/out on page load. If it's the latter, well, that's your code, so you'll have to program whatever you need to stop it from happening on page-load.
  5. You will get that warning every time you try to use the header function after you've already echo'ed stuff in your code. The code will have to be reorganized so that the header functions all come before any echo statements, then you should be fine.
  6. Jack, I'm not Larry, but I may be able to help. To help though, a little more context may be helpful. When you post the form data, is it posting to the same script you render the web page from or is it posting to a completely separate script? That will greatly affect how you display the posted data. Thanks.
  7. John, we talked about this in your last post, but you cannot do mathematical addition on strings. Whenever you do .value on a DOM form input, you are going to get a string back, even if it looks like a number. That will always be the case. And when you start trying to do fancy math with strings, you'll almost always end up with NaN (or not-a-number). NaN is not a syntax error, that's a logic error in that you're trying to do number math with strings. Please fix that problem and you should be okay.
  8. Your if condition says, "If the number of hours worked is less than 80 and less than 100, then do something." I think that's your problem. Anything under 100 hours will net you the same result every time.
  9. Speaking in high-level generalities, I think there are two parts to this: Identifying the events that will cause notifications to be created; and Deciding how to display notifications to the users. An example of #1 might be creating a notification for a topic creator every time someone posts something in one of their topics. For example, you might create a notification with the ID of the person who posted in the topic and then the ID of the topic creator, who will get the notification. You can then decide how you want to notify the topic creator. Do you want to send them an email? Do you want to do what Stack Overflow does and have an icon at the top of the site? Do you want both? If you go with the icon approach, then the simple thing to do is to do a check for unread notifications directed at a particular user every time a user loads a page on the site. You could display the number of unread notifications or something, and once they read the notifications, then the number goes down. That's the basic gist. If you want to go into more detail, then we can, but hopefully that's a good start.
  10. Here's a good starting point: https://www.w3schools.com/html/html5_geolocation.asp You have to do this in JS though, not PHP, and if the browser doesn't support navigator.geolocation, then you have to fall back on some PHP alternative, which is up to you to decide. Please note that the Geolocation API is built into regular JS, and it's separate from the Google Maps API, which is provided by Google. However, if you use the Geolocation API to get the user's current location, then you can feed the acquired coordinates into the Google Maps API from there. Make sense?
  11. John B, glad you got it working. The only thing I will say in response as a critique is that I think that things like the following are a bit difficult to understand: +regularPay+ +overtimePay People familiar with JS will know that +numInStrFormat will convert a String number to a Number number, but it does make the code a bit difficult to understand at first glance. In general, the easier code is to read, the better. All the same, glad you got it working, and it seems like you learned a lot along the way, which is great.
  12. Sounds good. I don't see a screenshot, but good luck with all of that, and let me know if you need anything else. Thanks.
  13. Hmmm... hard to say without a bit more context. I generally use Chrome for development, as I find the dev tools to be more to my liking. As such, I haven't used FF in a while to dev. With that said, I vaguely recall there being something in FF with the fact that if an error occurs before you load the console, then it wouldn't show the error in the console. Maybe try loading the console in FF first, then reloading the page and seeing if the error shows up. Beyond that, it's hard for me to assist without knowing exactly what you're doing and how. Thanks.
  14. John B, the browser console is your best friend for trying to debug JS issues/errors. I loaded up your code and instantly saw the following error: The following is line 23: var totalTaxes = document.getElementById ('totalTaxes').value = parseFloat(ficaTax+stateTax+federalTax*grossPay)/100.toFixed(2); An unexpected token error basically means that there is some invalid/unknown character in your code. This one is a bit interesting though in that the error is actually with the following expression: 100.toFixed(2) The reason this is a problem is because the 100. is ambiguous. Specifically, when you put a period right after a number like that, the JS parser doesn't know whether to treat that like a decimal in a number (e.g., 100.00) or as a dot used to invoke a method of the Number object (e.g., toFixed(2)). The easiest way to resolve this error is to remove the ambiguity by doing something like the following: (100).toFixed(2) With all that said, I still think there are some other logic errors in your code. If I were to make a recommendation, I would try to take a lot of the repetitive things you're doing and pull them out into one or more functions to decrease the likelihood of bugs in your code as well as make it simpler. As some examples, you could turn document.getElementById(str) into a function. You could also turn document.getElementById(str).value into another function that utilizes the first function. Furthermore, you could add a flag for whether to convert to a string or a number. Lastly, I would probably write a function to then set the value of a DOM input element. Putting all of that together, I may rewrite your code as follows: function calculate() { 'use strict'; var regularHours = getVal('regularHours', true), overtimeHours = getVal('overtimeHours', true), hourlyRate = getVal('hourlyRate', true), ficaTax = getVal('ficaTax', true), stateTax = getVal('stateTax', true), federalTax = getVal('federalTax', true), regularPay = to2Dec(regularHours * hourlyRate, true), overtimePay = to2Dec(overtimeHours * hourlyRate * 1.5, true), grossPay = to2Dec(regularPay + overtimePay, true), totalTaxes = to2Dec((ficaTax + stateTax + federalTax) * grossPay / 100, true), // Not sure about the correct parens here for the math. netPay = to2Dec(grossPay - totalTaxes, true); setVal('regularPay', regularPay); setVal('overtimePay', overtimePay); setVal('grossPay', grossPay); setVal('totalTaxes', totalTaxes); setVal('netPay', netPay); setVal('employeeName', getVal('firstName') + ' ' + getVal('lastName')); // Need the comma with first name first? return false; } function getVal(id, toNum) { var elem = gI(id); if (toNum) { return parseFloat(elem.value); } return elem.value; } function setVal(id, val) { gI(id).value = val; } function gI(id) { return document.getElementById(id); } function to2Dec(num, toNum) { // To two-decimal number if (toNum) { return parseFloat(num.toFixed(2)); } return num.toFixed(2); } function init() { 'use strict'; gI('form1').onsubmit = calculate; } window.onload = init; In my mind, that's a lot easier to debug as well as read. Please share your thoughts and any other questions you have. Thanks.
  • Create New...