Jump to content

justsomeguy

Moderator
  • Posts

    31,575
  • Joined

  • Last visited

  • Days Won

    77

Everything posted by justsomeguy

  1. Run the toggle function when any of the links are clicked.
  2. It's certainly simple for a seasoned developer, that's a basic part of using databases. If you don't know how to use databases then it's not going to be easy though. You need a form for people to submit whatever you want them to submit, and your code that processes the form needs to build a query with the appropriate WHERE clauses for your database structure. e.g.: SELECT * FROM people WHERE facility = 3 AND specialty = 10
  3. I use the MDN is the definitive Javascript reference. If I have a question about arrays I'll search for "mdn array" to get their pages about it.
  4. That's the wrong kind of copy. Javascript uses references for a lot of things like arrays and objects, so if you have a variable that's an array and set another variable to it, all you've done is made 2 variables that point to the same thing, that's what the reference is. You want an actual separate copy. It looks like you can use Array.from for that now: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from var copy = Array.from(sumArray); That's just a faster way to do this: var copy = []; for (var i = 0; i < sumArray.length; i++) { copy[i] = sumArray[i]; }
  5. You can make a copy of the array, or reverse it back.
  6. Did you try taking all of that code out of the loop? Right now, this is your loop: for (var i = 0; i < sumArray.length; i++) { if (sumArray[i]) { sum += Math.pow(2, i); } document.getElementById("s1").innerHTML = sum; document.getElementById("s2").innerHTML = sum; /*console.log(sumArray.reverse());*/ document.getElementById("demo").innerHTML = Number(sumArray.join("")); document.getElementById("posit0").innerHTML = sumArray [0]; document.getElementById("place0").innerHTML = sumArray [0]; document.getElementById("cijfer0").innerHTML = sumArray [0]; document.getElementById("value0").innerHTML = sumArray [0] * Math.pow(2, 0); document.getElementById("posit1").innerHTML = sumArray [1]; document.getElementById("place1").innerHTML = sumArray [1]; document.getElementById("cijfer1").innerHTML = sumArray [1]; document.getElementById("value1").innerHTML = sumArray [1] * Math.pow(2, 1); document.getElementById("posit2").innerHTML = sumArray [2]; document.getElementById("place2").innerHTML = sumArray [2]; document.getElementById("cijfer2").innerHTML = sumArray [2]; document.getElementById("value2").innerHTML = sumArray [2] * Math.pow(2, 2); document.getElementById("posit3").innerHTML = sumArray [3]; document.getElementById("place3").innerHTML = sumArray [3]; document.getElementById("cijfer3").innerHTML = sumArray [3]; document.getElementById("value3").innerHTML = sumArray [3] * Math.pow(2, 3); document.getElementById("posit4").innerHTML = sumArray [4]; document.getElementById("place4").innerHTML = sumArray [4]; document.getElementById("cijfer4").innerHTML = sumArray [4]; document.getElementById("value4").innerHTML = sumArray [4] * Math.pow(2, 4); document.getElementById("posit5").innerHTML = sumArray [5]; document.getElementById("place5").innerHTML = sumArray [5]; document.getElementById("cijfer5").innerHTML = sumArray [5]; document.getElementById("value5").innerHTML = sumArray [5] * Math.pow(2, 5); document.getElementById("posit6").innerHTML = sumArray [6]; document.getElementById("place6").innerHTML = sumArray [6]; document.getElementById("cijfer6").innerHTML = sumArray [6]; document.getElementById("value6").innerHTML = sumArray [6] * Math.pow(2, 6); document.getElementById("posit7").innerHTML = sumArray [7]; document.getElementById("place7").innerHTML = sumArray [7]; document.getElementById("cijfer7").innerHTML = sumArray [7]; document.getElementById("value7").innerHTML = sumArray [7] * Math.pow(2, 7); document.getElementById("posit8").innerHTML = sumArray [8]; document.getElementById("place8").innerHTML = sumArray [8]; document.getElementById("cijfer8").innerHTML = sumArray [8]; document.getElementById("value8").innerHTML = sumArray [8] * Math.pow(2, 8); document.getElementById("posit9").innerHTML = sumArray [9]; document.getElementById("place9").innerHTML = sumArray [9]; document.getElementById("cijfer9").innerHTML = sumArray [9]; document.getElementById("value9").innerHTML = sumArray [9] * Math.pow(2, 9); document.getElementById("posit10").innerHTML = sumArray [10]; document.getElementById("place10").innerHTML = sumArray [10]; document.getElementById("cijfer10").innerHTML = sumArray [10]; document.getElementById("value10").innerHTML = sumArray [10] * Math.pow(2, 10); document.getElementById("posit11").innerHTML = sumArray [11]; document.getElementById("place11").innerHTML = sumArray [11]; document.getElementById("cijfer11").innerHTML = sumArray [11]; document.getElementById("value11").innerHTML = sumArray [11] * Math.pow(2, 11); } You don't need to do all of that for every element in the array. I think you put that in the loop by mistake. Keep in mind also that Array.reverse is destructive, it changes the original array. Since you're trying to do that inside the loop that's another reason why it seems that you put too much code in there.
  7. I don't think I understand what the problem is, but it looks like the loop where you calculate the sum is too big. That loop should only calculate the sum, not change all of those elements on the page for each element in the arrray. You would keep reversing the array every time through the loop, which means that sumArray would keep changing.
  8. What do you mean by that? Just with the GA tracking cookies you can determine how to contact someone and gain some insight about their browsing habits? Is there a proof-of-concept of that or anything? I'm assuming you're not talking about the website administrator and just some random attacker trying to intercept traffic, I don't understand how that person would gain enough information to contact someone and act like they know them. Again, I'm looking for technical details on how an attack like that would work. I'm a technical person, I can understand the details. What I don't understand is how you think they can happen, in a technical sense. I mean, if the website is currently vulnerable, then wouldn't attacks like that be happening now? There's not, though. It IS possible to negate a specific attack, and websites that are not interactive and which don't do things like having people create accounts and log in and post content (like the w3schools site), are simple not vulnerable to several classes of attacks which rely on those kinds of things.
  9. 3 cookies on the home page, actually, and all of them are for Google Analytics. That's typically not considered sensitive information. What are you referring to technically? How does an attacker "intercept a link?" Are you referring to a MITM attack? Again, what are you referring to, technically? What something on the website can someone pretend to be an admin about, and how? And, technically, how would SSL/TLS prevent it? How does SSL/TLS prevent phishing attacks? Sure. How does SSL/TLS prevent that? Is the w3schools.com site hosting malware? If not, why bring this up? Again, since you're speaking with a technical audience, I would appreciate a technical description of the problem, and specifically how it can be rectified with SSL/TLS.
  10. It doesn't seem that difficult, but if you're expecting a ready-made thing that you just drop in and it works, you're probably not going to find that. The major pieces are a short blob of text, and an optional image, with a popup element to show them. That's the basics of it. How you get that text and that image is something that you can probably think about. Maybe one option is to send an ajax request for that other page (which will only work for pages on the same domain, as in Wikipedia), and find the preview text and optional image somewhere in the HTML, like the metadata in the head. Another option would be to build those anchor tags so that they use data attributes to include the text and image right in the link itself. There are probably other options you could come up with too. Maybe you have a database that has the text and image for every page on your site, for example. I haven't looked in-depth into how Wikipedia does it to know which solution they decided on. Since sometimes there is a delay, it sounds like they probably send an ajax request to the URL.
  11. You only have one post other than this one, what data are you concerned about?
  12. Like I said, you're missing the array index because the forum ate it. btnArray is an array, arrays do not have addEventListener methods. You need to access the elements in the array. btnArray[i].addEventListener
  13. Other than what I described? I'm sure you could come up with something that is more complex, but I don't know why you would. If you're looking for a built-in recursive object key search, I don't believe there is one. You would need to roll your own.
  14. You left out the [i] because you're not using code boxes on the forum when pasting your code. I just copied and pasted what you had there, I didn't notice that it was missing. The forum thinks you're trying to make italics. That's why we use code boxes to post code. If you want to know what that i is doing in parentheses at the end, just take that code apart. This code: addEventListener("click", (function(idx) { return function () { btnArray[idx].classList.toggle("marble"); console.log(btnArray[idx].classList.contains("marble")); } })(i)); is functionally equivalent to this: function return_listener(idx) { return function () { btnArray[idx].classList.toggle("marble"); console.log(btnArray[idx].classList.contains("marble")); } } addEventListener("click", return_listener(i)); That's a function that returns another function. The first version just uses an anonymous function instead of declaring the function with a name. That's called a closure, the purpose is to run that code inside a certain scope where the value of i (or in this case idx) doesn't change. Your first code had a problem because the loop would go through and add all of the event listeners, but the event listeners were using i. After the loop ends i is set to whatever is 1 greater than the length of the array, so when that function runs it uses the current incorrect value of i, not whatever i was set to when you defined the listener. The closure puts all of that in a different scope so that the value doesn't change.
  15. That's not valid HTML code, <a> tags and <img> tags don't go in the head section of the page. I'm not aware of any tag having a "download" attribute, either. If those files are already reachable on the web server then you just type the URL to the file in a browser to download it. I was assuming the files are not available in the web server root. If they are not, then you need to output the correct HTTP headers, and then send the contents of the file. HTTP headers have nothing to do with the head section inside an HTML document if you got confused about that. You use ASP or another server-side language to send the response headers. They tell the browser that you're sending a file of a certain type and size, what the name is, etc. They result in the browser showing the save/open dialog box.
  16. http://php.net/manual/en/datetime.add.php
  17. for (i = 0; i < btnArray.length; i++){ btnArray.addEventListener("click", (function(idx) { return function () { btnArray[idx].classList.toggle("marble"); console.log(btnArray[idx].classList.contains("marble")); } })(i); }
  18. If you're talking about Array.map, that's only available on arrays, not Objects. Maybe you can convert an Object to an array, but regular Objects don't have a map method. You can return the keys of an object though and loop through them that way. It sounds like you need a recursive function that checks if you're dealing with an array or object and searches appropriately. It would call itself if it found another array or object.
  19. If you're trying to do that with a regular multiple file input, it doesn't look like you can specify that on the client, you would need to check on the server. Otherwise, you can build your own form to add and remove file inputs with buttons or whatever. You would still want to validate that on the server though.
  20. Yeah, however you set up that array, that needs to be done before the code I wrote. I only included the definition of sumArray so that code would run, but you would use just that loop after your array is ready to convert from base 2 to base 10.
  21. Why not just wrap that last block of code in a function that you call whenever you're trying to check for events?
  22. You just need to write out an img tag with the correct URL to the image.
  23. I don't think you need the individual functions for each one, I think you only need the main function. You could also just use a loop to go through the buttons and put a 1 in each array index that is selected. You can get the sum by looping through that array, e.g.: var sumArray = [0, 1, 1, 0, 1]; // create this yourself from the buttons var sum = 0; for (var i = 0; i < sumArray.length; i++) { if (sumArray[i]) { sum += Math.pow(2, i); } } console.log(sumArray.join('') + ' is ' + sum);
  24. I see one opening <tr> tag and 3 closing </tr> tags, so the first step is probably to figure out when you need to start a new row.
  25. There's not enough code to tell what the problem is, the problem is either in the form processing code that is updating every comment for some reason, or the problem is in the displaying code.
×
×
  • Create New...