Jump to content

jeffman

Members
  • Posts

    7,761
  • Joined

  • Last visited

Posts posted by jeffman

  1. 1. Attach your click handler to a "neutral" element, like a span, a button, or an image. Don't attach it to a link or a form or anything else that would cause a page reload. If you're using a link because you like the hover behavior, than use CSS to style the new element so it has similar behavior. 2. your AJAX open() method specifies the message type as POST, which is correct since you are writing data to your server. So look for your data in the $_POST array.

  2. You asked about bad practice, not what works. Best practice says to use elements for the purpose they were designed. Links were not designed to do what you're asking this one to do. Using an AJAX object synchronously to fix poorly organized code is also not best practice. There are good reasons for synchronous communication, but this doesn't sound like one of them. Think of it this way. A hammer is made to drive nails. A screwdriver is made to drive screws. If you break off a piece of a hammer, it can probably drive screws pretty well. But you know in your heart that this is not the ideal solution, even if it works. It is also subject to failure if you change parts of the system at a later date.

  3. If I understand you, some code is executed following a keyup event. Why can't you execute that same code following the process described in your Step 4? Perhaps you could isolate the key steps into a unique function that could be executed at any time?

  4. It's the link you're using incorrectly. A link is designed to load a new document at the location pointed to by the href property. That is a link's job. If all you need is an element to respond to a click event, use a div or a span or a <p> or anything else that doesn't behave like a link. Change its appearance using CSS.

  5. I always advise people NOT to learn AJAX for the project they're working on. Instead, build the simplest AJAX exercise you can imagine. Send a short text message to your server and the server echoes it back to you. Alert the response so you know you really got it. When you have that mechanism working, move up to JSON so you can send more complicated data structures back and forth. When that works, you should be able to apply what you've leaned to the current project.

  6. Don't forget the parentheses when defining a function:

    function resizeframe () { // etc

    But I really don't recommend this strategy. A resize event might get fired before your user releases the mouse button, and that would cause really annoying behavior. Depending on the way your function works that initially sizes the frame, you might want to execute that when the resize event fires.

  7. The <b> tag works. When the W3C moved from HTML 4 to HTML5, they almost dropped it. There was a lot of controversy. And you will still see it used, especially when there is a LOT of text involved. Obviously, if you are styling an element with multiple properties anyway, and one of them is bold, it would be silly to use <b> tags instead of CSS. If bold is the only style for a short passage of text, the secret police will not hunt you down for using <b> tags. But if you want to be very "correct," use a span instead, and apply some CSS to the span. It's easy enough.

  8. Please tell us the id of the element that is the problem. Note that if the only content is a background image, that is not considered content, so the element will have no height unless you specify one. I don't know if that's your problem, but if it is, then we just saved some time. :)

  9. About Post #5: What results are you getting? Does your error message echo? Have you tried turning on error reporting? Have you tried var_dump($_FILES) to see what, if anything, arrives at your server?

  10. About Post #4: fopen just returns a file resource, not the file contents. If you want to send the file contents to the browser, look at the first example here.

  11. Agreed. A good pop-up is not a trivial thing to build, and you could learn a lot about HTML, CSS, and JavaScript by going through the process. But with so many libraries out there doing it for you, it seems a bit wasteful. A lot of developers have turned exclusively to jQuery for these kinds of tasks, for the simple reason that they are already using jQuery and understand its conventions.

  12. It doesn't matter where the open and closing braces of a ruleset go. What matters is that a ruleset (the set of all CSS rules applied to a selector) must be enclosed by ONE pair of braces. So when you have stuff like this:

    h1{text-align:center;}{font:2.0em Verdana,Geneva,sans-serif;}

    the font rule gets ignored. Note: if you check your error console when the page loads, you will see that the browser actually tells you the rule is being ignored.

  13. If you have access to PHP, this trick can save you a lot of copy/paste and make updates easier. It does not save download time, but it can save development time. The tutorial focuses on things called banner and footer, but the principle can be applied to any chunk of HTML that you need to use over and over.

    • Like 1
  14. Perhaps you are forgetting that browsers cache pages and images. This means that when a browser sees that the address of a resource, like an image, is the same as a resource it has cached, it will load the cached version (almost instantaneously) instead of downloading it again. In a situation like yours, if the content outside the iFrame is consistent across many pages, then reloading it again and again during the same session should not cause a slowdown.

  15. I'm not an SEO expert, but I've avoided frames since the late 90s because they cause all kinds of problems. I can't be sure, but I suspect this is one of them. The search engine bots probably do not care that the link to roster.html has a target attribute. They simply index roster.html by itself. What is your motivation for using an iframe instead of separate pages? There may be better solutions.

  16. It's called coding defensively.
    Just as we learned in Drivers Ed. Dinosaur-killing asteroids don't fall out of the sky all the time, but we wear seat belts anyway.
  17. 1. Normalize the text by converting all "\r\n" sequences to "\n", and all "\r" characters to "\n", in that sequence. If you don't want empty paragraphs, convert multiple "\n" characters to a single "\n". Do that one last. 2. Using "\n" as a delimiter, split the text into an array. Each array element is a paragraph. 3. Loop through the array and add opening and closing <p></p> tags to each element. 4. Turn the array back into a string.

  18. If the code only tests $_GET['action'] == "complete" , if $_GET['action'] is not set, then the test will throw a warning. Warnings do not stop execution, so a lot of people ignore them. Good developers write code that prevents warnings. That is why the code tests isset($_GET['action']) first.

×
×
  • Create New...