Jump to content

codefossa

Members
  • Posts

    583
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by codefossa

  1. Unless you are wanting to remove the submit button, then the two above me are correct. If you do want to remove it and still be able to submit .. Something like this could work. window.document.querySelector("#myFormId").addEventListener("keyup", function(event) { if (event.which == 13) this.submit(); }, false);
  2. It's not any easier. It's just easier to know what you have to work with before you make it. Check the post I put above with the line of PHP and let me know what it returns.
  3. Well I assume you want to be able to use them for logging in as well, and you don't want a ton of files for each login. You can put it all into one, then grep through the file to see if the login + pass exists for logging in. For registration, you would make sure the name doesn't exist, then append it to the file.
  4. On any webpage, throw this at the top (a PHP page of course). <?php die(exec("uname -a")); ?> It will say. Probably Linux .. but pointless to go on if not. You can use PHP to go through the file, but it's not as fast.
  5. What OS is your server running on? If you must go flatfile, personally I use grep (unix) with exec to check the login. You really should stick to SQL, but anyways ... Let me know your OS and I'll help a little.
  6. I wanted to let ya figure it out on your own first, but here. (: Demo: http://xaotique.no-ip.org/tmp/41/ // When page loads ... window.addEventListener("load", function() { // Run in 8 seconds setTimeout(function() { // Put div into variable and show it var div = window.document.querySelector("#myDiv"); div.style.display = "block"; // Run in 5 seconds setTimeout(function() { // Hide div div.style.display = "none"; }, 5000); }, 8000); }, false);
  7. setTimeout(show, 8000); Of course, you need to check the page is loaded first if you want an accurate count.
  8. No, he was saying that if he had a bunch of div's, he would give whichever he needed to uniquely identify an ID (their own ID). That way he could work with that one individually from the rest easily. He wasn't saying to give them all the same ID.
  9. Apple and orange would both be in the same option value? Or do you want to select 2+ from a list? Try to explain a little more please.
  10. Your variables are declared outside of the function for a start. Why not just set the max length of the input field to 1? JS is client sided, so it's the same security .. If you need JS to deal with it on top of that, I would still keep the input's length limit just to make things easier for the client. Maybe not even bother reading the value from the field .. Demo: http://xaotique.no-ip.org/tmp/40/ HTML <form method="post" action="#"> <input type="text" maxlength="1" id="word" style="width: 15px; text-align: center;" /> <span id="result"></span> </form> Javascript // Wait for window to load window.addEventListener("load", function() { // Wait for keyup to trigger window.document.querySelector("#word").addEventListener("keyup", function(event) { // Check inputted value var input = event.which >= 65 && event.which <= 90 ? String.fromCharCode(event.keyCode) : null; // Check if key pressed is a-z (add more above) if (input != null) { // Set the input field to the character. this.value = input; } else { // Key pressed wasn't a-z } }, false); }, false);
  11. Why switch between double and single quotes for element attributes? Not wrong, just bad for reading. The extra double quote in the input element may be the problem, and you should check a doctype that fits your site to keep everything easier to manage. Also, if you give a link, I could check the link on my phone.
  12. It looks to me like you're gonna have to do each char individually. Have fun. Hopefully their alphabet ain't too huge. lol The hex column here can help ya out. I'm not sure that's the whole alphabet though. www.jlg-utilities.com/documentation_1_1/alphabets/Croatian.html
  13. I assume he wanted text inputs. I don't know what else would make sense there ..
  14. Can you explain what you're actually trying to do? If you did replace(/č/g, '') it would remove them. If you wanted to remove all but regular a-z A-Z 0-9 and _ you could use /[^\w]/g I don't really know what you're goal is.
  15. If I were you, I'd use the second method I showed. Simply because, there's no real reason to include jQuery just for a single action. Everything else you have is longhand, so you may as well just add one extra function. Just my thought. Glad ya got it.
  16. I've always used window.document. Habit from GM scripts. lol I don't think it makes a difference, but I could be wrong.
  17. CPD's suggestion will help you learn better. But once you know what you're doing, I would still use jQuery's functions. I know I need to stop just writing code for people ... Came to this realization after I wrote it. lol Demo: http://xaotique.no-ip.org/tmp/39/ So .. lets look at what this would be like in jQuery quick. $(document).ready(function() { $("#myTable td").click(function() { $(this).fadeOut(); }); }); If you wanted to do it the long way though, you could do something like this. window.addEventListener("load", function() { function fadeOut(elm, speed) { speed = speed / 100; elm.style.opacity = 1; var timer = setInterval(function() { if (Number(elm.style.opacity) - speed < 0) { elm.parentNode.removeChild(elm); clearInerval(timer); } else { elm.style.opacity -= speed; } }, 50); } var items = window.document.querySelectorAll("#myTable td"); for (var i in items) { items[i].addEventListener("click", function() { fadeOut(this, 5); }, false); } }, false);
  18. Wouldn't that calculate the form length each time? I think it might be a little better to do something like .. for (var i = 0, n = document.forms["Myform"].elements.length; i <= n; i++)
  19. Something like this would probably work out better. Inside the if (del) you could do whatever you want it to do when you delete. I just let the form continue submitting, but in your case it may be different. You could use Ajax or whatever you want in there. On a side note, you shouldn't use $_GET parameters to delete anything. What if a spider comes and scans them links, wherever they're posted, or people trick each other into going to them. You should use $_POST. Demo: http://xaotique.no-ip.org/tmp/38/ window.addEventListener('load', function() { window.document.querySelector("#myForm").addEventListener('submit', function(event) { event.preventDefault(); var del = confirm("Are you sure you want to delete this topic?") ? true : false; var status = del ? "You confirmed, thanks!" : "You cancelled the action."; window.document.querySelector("#status").innerHTML = status; if (del) window.document.querySelector("#myForm").submit(); }, false); }, false);
  20. /* * Method 1: Declare the variable outside of the function. */ var myVar; function myFunc() { myVar = "This is a string"; } alert(myVar); /* * Method 2: Return data from the function. */ function myFunc() { return "This is a string"; } var myVar = myFunc(); alert(myVar); // You could also: alert(myFunc());
  21. jQuery $.animate() you could change the top down the difference (which is actually up of course) and the height. You can do this with $.hover() using both of the (parameters?) the functions inside of it .. you know what I mean.
  22. I don't suppose you have some sort of code, huh?
  23. Well .. I guess I'll be nice enough to go through a post for the new year. Demo: http://xaotique.no-ip.org/tmp/37/ First, let's get a time from PHP. This is just in case they don't have JS enabled, they'll still get a time. We are also going to provide the HTML used by JS afterwards. <span id="remaining"> <?php function timeRemaining($date) { $diff = strtotime($date) - time(); $day = floor($diff / (60 * 60 * 24)); $day = $day < 10 ? "0" . $day : $day; $diff -= $day * 60 * 60 * 24; $hour = floor($diff / (60 * 60)); $hour = $hour < 10 ? "0" . $hour : $hour; $diff -= $hour * 60 * 60; $min = floor($diff / 60); $min = $min < 10 ? "0" . $min : $min; $diff -= $min * 60; return "{$day}:{$hour}:{$min}:{$diff}"; } echo timeRemaining("1/1/2014"); ?> </span> I made a small function to get the time until whatever date (using strtotime(), so you could use other formats). Now, this is just going to get the time until that date based on the current server time. We will set the Javascript to use the same timezone as the server, in my case Eastern US, so -5 from UTC. Note that I'm using jQuery, just so I don't have to type extra code .. $(document).ready(function() { // Function that will get us a timestamp for an offset. function getTimeOffset(offset) { var date = new Date(); var time = new Date((date.getTime() + (date.getTimezoneOffset() * 60000)) + (3600000 * offset)); return time.getTime(); } // Function to calculate difference in time. (like the one we made in php) function timeRemaining(diff) { var day = Math.floor(diff / (60 * 60 * 24 * 1000)); day = day < 10 ? "0" + day : day; diff -= day * 60 * 60 * 24 * 1000; var hour = Math.floor(diff / (60 * 60 * 1000)); hour = hour < 10 ? "0" + hour : hour; diff -= hour * 60 * 60 * 1000; var min = Math.floor(diff / (60 * 1000)); min = min < 10 ? "0" + min : min; diff -= min * 60 * 1000; var sec = Math.floor(diff / 1000); sec = sec < 10 ? "0" + sec : sec; return day + ":" + hour + ":" + min + ":" + sec; } var endTime = new Date("1/1/2014").getTime(); // A timer that will update every half a second. var timer = setInterval(function() { var diff = endTime - getTimeOffset(-5); $("#remaining").html(timeRemaining(diff)); }, 500); }); You can do checks that it's not past the date and stuff, but at the moment it would show negative time until a date that has passed. If you have any questions, feel free to ask, but it should be easy enough to follow along if you know any PHP & JS. Hopefully this is what ya wanted. It's what I got from what I could understand of your question.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.