Jump to content

codefossa

Members
  • Posts

    583
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by codefossa

  1. Instead of using echo inside of your while loop, just put the content into a variable. Also, javascript alerts use \n rather than <br />. It can't display HTML. <?php $content = ""; while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) { $content .= "Page ID :{$row['page_id']}" . "\n" . "--------------------------------" . "\n"; } echo ' <script type="text/javascript"> window.addEventListener("load", function() { alert("' . $content . '"); }); </script>'; ?> Though, if you wanted to alert each one separately, you would just open the <script> before the while loop, close it after, and each row would echo out an alert.
  2. For that I would give what I used in the example, or something similar. The only problem is without the check for characters, it will show 1 word for an empty string. str.split(/\s+[^$]/).length Split by spaces (no matter how many are together) as long as they're not at the end of the string. You could probably add tabs and whatnot in there as well, but for regular word counting, that should suffice. Edit: Oops, that checks for a physical "$". Hmm .. maybe /\s+[^\s]/ would be better? My example only worked correctly because there's no character after spaces at the end unless you put the $, then you see the problem. "This $would fail." Maybe you got a better idea? Not sure OP has checked back though.
  3. Unless they use double spaces at any time, usually after a period. They may have a space(s) at the end of the string, or for some reason indent with spaces. It just wouldn't return accurately for a number of reasons, which you should plan for if you're using it publicly.
  4. Demo: http://lightron.tk/tmp/53/ HTML <textarea id="input"></textarea> <div id="result">0 Words</div> Javascript // Wait for the page to load. $(document).ready(function() { // Define some default text. var defaultText = "Enter some text to test. (:"; // Set default text on page load and lighten text color. $("#input") .val(defaultText) .css("color", "#555"); // When you focus, remove default text and darken text. $("#input").focus(function() { if ($(this).val() == defaultText) $(this) .val("") .css("color", "#000"); }); // When they let go of a key .. $("#input").keyup(function() { // Grab the current value. var val = $(this).val(); // Split by spaces and count the words. var words = val.replace(/\s+/, '') == "" ? 0 : val.split(/\s+[^$]/).length; // Show number of words. $("#result").html(words + " Words"); // Color green if valid, red if invalid number of words. if (words >= 400 && words <= 1000) $("#result").css("color", "#0C0"); else $("#result").css("color", "#C00"); }); });
  5. Just a note. The all caps and mix of big/small letters is irritating to people who have troubles reading. You should really also listen to kricken. Disabling right-click to protect your source is useless. It doesn't even stop most people who don't understand well how things work, since in just about every popular browser, it's an option in the menu. For people who do, JS ain't going to do anything anyway, as if we were to want to scrape or anything like that, it's not even executed. I use right-clicks all the time for copying links and whatnot. Opening links in a new tab I do with a middle-click, but you're also blocking people who do right-click to copy and paste, and many other legit reasons. Blocking right-clicks should stay in the past, because there's no good use for it any more.
  6. No left click on the whole document? Then you couldn't click links or anything. You would have to have a single page site, or make exceptions for everything you want to click. I don't see the point of blocking a left click though.
  7. If you're doing a game, you may find other uses for $.data() as well. jsFiddle: http://jsfiddle.net/Re7jQ/ Javascript / jQuery $(document).ready(function() { $("selectLink").click(function(e) { e.preventDefault(); if ($(this).data('disabled')) return false; $(this).data('disabled', true); window.open($(this).attr("href"), "_blank"); }); }); Edit: I didn't realize this is your safety to selling items. While it will stop the average user, Javascript is not going to prevent people from exploiting it. You need to check server-side to assure they are not selling an item they don't have.
  8. Demo: http://lightron.tk/tmp/52/ We'll start with the HTML. We'll use two BUTTONs and two DIVs. <input type="button" class="change" rel="welcome" value="Hello" /> <input type="button" class="change" rel="goodbye" value="See Ya!" /> <div class="content" id="welcome">Hey! Welcome to the page.</div> <div class="content" id="goodbye">Come back soon.</div> Lets jump over to some CSS now. We want to hide the goodbye DIV by default. #goodbye { display: none; } Now lets add some Javascript. I'm gonna use jQuery. // Allow the page to load $(document).ready(function() { // Wait for a button to be clicked $(".change").click(function() { // We're gonna use the value of the rel attribute for the ID var item = $(this).attr("rel"); // Hide all of our DIVs and show the one we want. $(".content").hide(); $("#" + item).show(); }); });
  9. Without using Ajax, you're going to cause a page load when the form submits. I'd suggest using jQuery if you wish to go that route. Check out $.post(), and you should figure it out pretty easily. They have examples on the jQuery site.
  10. CSS white-space: nowrap; Your HTML Revised <div style="overflow-x:scroll; width: 300px; height: 100px; white-space: nowrap;"> As you can see, once there's enough text in this box, the box will grow scroll bars... that's why we call it As you can see, once there's enough text in this box, the box will grow scroll bars... that's why we call it a scroll box! You could also place an image into the scroll box. a scroll box! You could also place an image into the scroll box. As you can see, once there's enough text in this box, the box will grow scroll bars... that's why we call it a scroll box! You could also place an image into the scroll box. <img src="1.JPG" width ="10" height="10" /> </div>
  11. That removes the value and comma that goes with it. But I did make one mistake. That will replace like "50,23" and leave "523". Try this. str.replace(/^0,|,0(,)|,0$/g, '$1')
  12. This works .. str.replace(/0,|,0$/g, "")
  13. Just to give an example of what Adam said. JSFiddle: http://jsfiddle.net/gfFG9/ function removeCSV(elm, pos) { var arr = elm.value.split(','); arr.splice(pos, 1); elm.value = arr.join(','); } var element = window.document.querySelector("#people"); removeCSV(element, 0); // Remove the first value. /* * 0, 1, 2, 3 .. for elements. Element 1 is the second, 2 * the third, and so on. */
  14. Yes, but you didn't really explain much or give any code to go off of. From the sounds of it, you'd be good using GIF animated images and using JS to move the image. You can easily simulate walking, running, jumping, etc. with that. There are also game frameworks written for JS. You may want to look into that some. And if nothing else, jQuery would make this a bit faster and easier.
  15. <html> <head> <title>Xaotique - JS Page</title> <script type="text/javascript"> // Wait for the page to load before executing JS. window.addEventListener("load", function() { // Set the datestring for comparison. var datestr = window.document.querySelector("#datestr").innerHTML; // Compare it .. if (datestr == "June 2013") { // Create the button and set attributes. var myButton = window.document.createElement("button"); myButton.innerHTML = "Click Me!"; myButton.id = "myButton"; // Append the button to the body. window.document.body.appendChild(myButton); // Wait for the button to be clicked. myButton.addEventListener("click", function() { var name = "MS", job = "QA"; alert("Welcome " + name + ", the " + job + "!"); }); } }, false); </script> </head> <body> <p id="datestr">June 2013</p> </body> </html>
  16. You can only have an ID be used once per page, so are you sure you don't want to use a class? I assume there are more than one. But, as for what you asked .. http://jsfiddle.net/UwDEA/
  17. http://www.php.net/manual/en/features.file-upload.post-method.php And as far as using JS to avoid the refreshes and whatnot, you could check out $.submit() and prevent it, then use $.post().
  18. Lines 49 - 55: http://jsfiddle.net/qX6k8/1/
  19. Why bother to find and disable anything inside of a tag if you're hiding it? If they're going to edit it to do whatever, they could easily remove the disabled attribute, if it even affects the form submission. And, you may want to check out removing an element, depending on what you're doing.
  20. $.scrollTop() and you can use it in $.animate() if you want it to actually look like you're scrolling, rather than just appear there.
  21. You should check out jQuery's $.get() and $.load().
  22. setTimeout() rather than setTimeOut() should work. Although, you also need to define your seconds variable. $(document).ready(function() { var seconds = 5; setTimeout(function() { $("#content").load("update.php"); }, seconds * 1000); });
  23. This should work. http://jsfiddle.net/6eJuB/ window.document.querySelector("#elmId").addEventListener("click", myFunc, false);
×
×
  • 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.