Jump to content

codefossa

Members
  • Posts

    583
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by codefossa

  1. It seems my identity has been revealed. I don't see the problem with showing them what it is here so they can get used to looking for things before the line shown.
  2. You could do something like this to set the rate to 0 if it's going to attempt to divide by 0. $rate = $tek[0][1] != 0 ? $tek[0][0] / $tek[0][1] : 0; But, you may wish to just return 0 if it's not going to work. if ($tek[0][1] == 0) return 0; $rate = $tek[0][0] / $tek[0][1];
  3. You could try something like this. Using $.on() instead. Link: http://jsfiddle.net/JtXVR/7/ $(document).ready(function() { $("body").on("keyup", ".txt", calculateSum); function calculateSum() { var sum = 0; $(".txt").each(function() { if (!isNaN($(this).val()) && $(this).val().length != 0) sum += parseFloat($(this).val()); }); $("#sum").html(sum.toFixed(2)); } });
  4. This is Javascript, not Java.
  5. Maybe just use a function that checks both rather than two functions to check the same thing. JSFiddle: http://jsfiddle.net/LKr8G/ // The input fields. var inputs = $("input[type='password']"); // The output message element. var output = $("span"); // Run the check as the password is typed. inputs.keyup(check); // On change, run the check. inputs.change(check); // Function to compare passwords. function check() { // Check if the fields' values are the same. if (inputs[0].value == inputs[1].value) { // Yay! They match. output.html("Passwords match!").css("color", "#090"); } else { // Let's tell them the bad news. output.html("Passwords do not match.").css("color", "#900"); } }
  6. You could save a message to a file and just have JS call a PHP page loading the contents of that file. Another option is to just run the script in a terminal, where echoing out a string will show right in front of you live.
  7. From a quick Google search. http://www.esrun.co.uk/blog/disguising-a-facebook-like-link/
  8. Well, it's by far easier with jQuery if you want to pass form information or something you can use .serialize(). You could use .serializeArray() to keep things easier and cleaner. It sounds like all you want to do is use window.location and set it to something like "http://mysite.com/?var=this&var2=that". You can say "screw jQuery", but the truth is that it makes just about everything so much easier. That is the main thing you should have paid attention to from his post. If you want help, you should put some effort into trying it and show us that you have. Just coming and asking for code isn't going to get you very far. There's a freelance section for that stuff. Also, no. You don't need jQuery for anything. It makes things a hell of a lot easier though, and a lot of times lets you do much less work for the same or better result. You don't need a lawn mower to cut your grass. Scissors work, but it would be a pain in the ass.
  9. You're welcome. If you get stuck anywhere, feel free to ask. I should note that you could make that 1 query by appending to your query in the foreach loop instead of doing a new query each time. It would make a bit more sense. Of course, escape everything and whatnot when you do it to avoid anyone taking advantage of that, even though where it sounds like you're using it that wouldn't exactly be a problem. Just better to be safe.
  10. 1. It's the same as an if statement for what you're doing. || being OR will return if a is true or b is true, then true .. else false. 2. You don't have OR operators in anything but booleans. It seems as if you think you may return either false or true with that, but it's not the case. It will always return true because this or that is true. In your case, the or 2 == 2 will cause it to be true. 3. Yes. 4. An OR operator. All you're doing is returning a statement's result. function example(n) { if (n > 0) return true; return false; } function example(n) { return n > 0; }Both of them do the same thing. In your case, all you did was use an OR in your if statement. if (n > 0 || n == 0)You can return that as well, and get the same result.
  11. Without going into the security and whatnot you'll need to do such as logins or whatever for the person taking attendance. Here's a little example. Demo: http://lightron.org/tmp/51/ index.php - Making the Form <?php /* * By this point you should have the list of users drawn from * the database. I'm just going to use $users for this. * * They should have an ID and name which would be for the use of * the one taking attendance. */ $users = array( 23 => "Arnold Jackson", 41 => "Jack Thompson", 43 => "James Camron", 44 => "Cindy Loo Hoo", 56 => "Alison Spangler" ); ?> <form id="attend" method="post" action="#" autocomplete="off"> <?php foreach ($users as $id => $user) echo '<input type="checkbox" name="present[]" value="' . $id . '" /> ' . $user . '<br />'; ?> <input type="submit" value="Send" /> </form> <div id="status"></div> script.js - Submit with Javascript (Using jQuery) $(document).ready(function() { function disableForm(disabled) { $("#attend").find("*").attr("disabled", disabled); } $("#attend").submit(function(e) { var postdata = $(this).serialize(); disableForm(true); $.post('attend.php', postdata, function(data) { $("#status").html(data); disableForm(false); }); return false; }); }); attend.php - Deal with Submitted Data <?php if (isset($_POST['present'])) { foreach ($_POST['present'] as $user) { /* * Now I'm making the assumption that you have a table set up and * it defaults the user to 0 (not present) until changed witht he form. * * $sql = "UPDATE `table` SET `present` = '1' WHERE `id` = '{$user}' LIMIT 1;"; * mysql_query($sql); */ // Just to show something back on the form. echo "{$user} is Present<br />"; } // Probaby better to go with something along the lines of this. echo "<br /><br />The form was successfully submitted."; } ?>
  12. Thanks, but the problem is I'm collecting all of the posts and users on the page. When I select /node() it will split up the posts and I really have no way to determine which post goes with which user. An alternative would be if it were possible to return the HTML and then I could remove the quotes with PHP. I ain't sure if you can return plain HTML though.
  13. So I'm stuck on an issue while parsing a forum, I want to ignore the quotes and only read the message from the posted user. So .. Imagine I have this HTML loaded. <div class="main"> <div class="quote"> Some stuff written here .. </div> More written here and a <b>bold word</b> or two. </div>So, what I want to return is: More written here and a bold word or two.Which is returned when I evaluate the path, but it also returns what's in the quote and I ain't sure how to ignore that. Using /text() will ignore the bolded words in this example. Thanks for any help.
  14. Just create a new bookmark, then add the javascript after "javascript:" in the location. Example: javascript:alert("Snoopy");void(0);Adding void(0); to the end will stop your code from causing a refresh or location change accidentally.
  15. If $_POST['r_submit'] is set or $other_post == $x then do nothing. I think you want to use OR (||) rather than AND (&&).
  16. I showed getting the value on change. That way it had a trigger you could play with. The value is grabbed: $(this).val()And $(this) points to $("select") in my example. I only have one select tag, so it's fine to use as a trigger. Although, it's pointing directly to the one that was triggered. If there were more select tags, it would still point to the one you changed in that example. You were pointing to the option tag, when you can simply call the value of the select element.
  17. Just select the select, rather than the option. Tested working in Firefox & Chrome: http://jsfiddle.net/XR6DT/ I'm a Linux user, so I can't really test IE, but it should work as well.
  18. If you want to remove the one named "tmp" with a value "aaa" you would want something like this. $("form input[name = 'tmp']").each(function() { if ($(this).val() == "aaa") $(this).remove(); }); But, maybe you just wanted to remove the first "tmp" field? $("form input[name = 'tmp']:eq(0)").remove(); It just really depends on the situation, and you didn't provide much information on what you actually want to accomplish.
  19. Yes, you would use them basically the same way. function myFunc(i) { $.ajax( { // Something .. }).done(function() { // Success - Call Next myFunc(i + 1); }).fail(function() { // Failed - Retry? myFunc(i); }); }
  20. $.ajax({ // Some stuff .. }).done(function() { // Call Next }); You can use .done() for successful, .fail() for unsuccessful, or .always() to always trigger after it runs. You could use .done() and .fail() together I believe to do something depending on which occurs.
  21. If you want something to happen after a certain time, you don't want to rely on client side detection of the end. Ignoring the possibility of someone simply changing it to zero, if nobody triggers it, it would fail as well. You should give what Irate said a shot, using cronjobs. This way the server checks periodically if the time is up and triggers whatever to happen. Nobody can cheat it, and you rely on nobody but yourself. If you set an explicit time, be sure to pay attention to the timezone set on the server.
  22. I'm not really sure what you want to do. This would basically follow your pseudo code as far as I can tell. function ready() { function runTest() { var x = "that", y = prompt("Type anything but that!"); if (x != y) { if (confirm("Do you wish to continue?")) { alert("Let's go!"); return true; } else return runTest(); } return false; } if (runTest()) alert("We're gonna keep going."); else alert("Let's stop."); } window.addEventListener("load", ready, false); So, if you wanted to load a function in PHP, it would need a page you can call, then JS will grab the output of the function. I would suggest using jQuery to make this easier. Something like this maybe? $(document).ready(function() { function runTest() { var x = "that", y = prompt("Type anything but that!"); if (x != y) { if (confirm("Do you wish to continue?")) return true; else return runTest(); } return false; } if (runTest()) { var div = $(document.createElement("div")).load("/mypage.php"); } else alert("We've stopped .."); }); All of this is untested, but it's just kind'a to give an idea. I'm not really sure what you want to accomplish, so hopefully this helps.
  23. Along with including jQuery, you will want to wrap your JS in $(document).ready() function so the page loads before attempting to use any of the data in it.
  24. He's right. I didn't test it, just threw it up quick. When storing it in a variable, you need to use single quotes to hold the new line so "\n" gets sent rather than the new line character. $works = "one line" . '\n' . "and another"; $doesnt = "one line" . "\n" . "that new line char broke the script";
×
×
  • 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.