Jump to content
Larry Ullman's Book Forums

markifornia

Members
  • Content Count

    112
  • Joined

  • Last visited

Everything posted by markifornia

  1. This one's a simple question, I am just trying to figure out where the supplementary markup code for the code is? I am fine coding this myself though, I was just making sure otherwise I will also check the source files provided on Larry Ullman's site. Figure 8.7/8.8 displays the form on reporting events on page 292. Thanks, Mark
  2. Thanks Hartley, could very well be the reason why on page 287, both events are passed to the function. U.addEvent(U.$('comments'), 'keyup', limitText); U.addEvent(U.$('comments'), 'change', limitText); Page 288 goes into detail about accessibility with introducing a concept known as "pairing events". I guess the above is similar to the concept. <a href="somepage.html" id="link">Some Text</a> // javascript: addEvent(document.getElementById('link'), 'mouseover', doSomething); addEvent(document.getElementById('link'), 'focus', doSomething); I guess th
  3. This chapter discusses a topic on keyboard events. I have provided links to my dev website. On page 284, the "change" event is added to the U.addEvent method. U.addEvent(U.$('comments'), 'change', limitText); http://www.sandiegowebcreative.com/text.html On page 284, the "keyup" event is added to the U.addEvent method. U.addEvent(U.$('comments'), 'keyup', limitText); http://www.sandiegowebcreative.com/text2.html I don't notice the difference between the two. I receive the same results from my browser, or I may not be noticing that which i
  4. You've both pointed out some advanced concepts just beyond me in my learning process, but I see both ways working. I've built some forms just using PHP and Javascript where I'll have the form dynamically load the form (including javascript validation routines), and then have a noscript version of the form handled by PHP (the fallback, with validations). So here, I have done the same thing - two versions - let me tell you though, this method has worked successfully against spam bots. My forms are completely CAPTCHA free. So I drew a parallel to my approach. But here I am learning how to bui
  5. ajax.open('get', dept_results_ajax.php?did=' + encodeURIComponent(did))); My question is actually a simple one. To create an ajax driven web application are two similar php files necessary? ie dept_results.php (non ajax version) and dept_results_ajax.php (ajax version)? Can there be one file that can also be the fallback? I may be getting ahead of myself, as I am only on chapter 3. I am just trying to see how others have built their ajax web applications. Thanks, Mark
  6. That threw me off too, I have no idea what the text is referring too. So they are no longer present, what exactly is no longer present? Whats reset? I did figure the same thing, in that learning by doing would get my head around it hopefully in the near future. As I do get hyperfocused into these things. As for now I'll just do what the book says and add e.preventDefault () and e.returnValue = false
  7. function handleForm() { // Do whatever. if (errors) { return false; } else { return true; } } The text goes on to say "Conversely returning anything other than false allows the default event behavior to occur (in that case, the forms submission). The problem with returning false to prevent the default browser behavior is that it only works reliably when the event listener was registered using the traditional approach. For example say event.js added the form submissison event handler using the newer approach. U.addEvent(U.$('theForm'), 'submit', setHandlers); With that c
  8. Again, another simple question but this one is regarding the example in the book as follows: function someEventHandler(e) { // use e. } The text says "Often the argument is abbreviated as just e or evt, short for event." Are "e" and "evt" reserved keywords? Or is the text just saying that "e" and "evt" are used commonly as the argument? Any argument could have been used such as "x" and "y", correct?
  9. I just took a look at Hartley's attached diagram. wow, I would have expected more native objects. Sure there are arrays, but this nice visual makes things much clearer. Thanks for that.
  10. My apologies for dragging this on with a bland example (I'm still learning this whole deal about objects), but in this simple example dog has 3 properties - color, weight, and name. And then it has one method which is bark. var color = 'brown'; var weight = 50; var name = 'fido'; var dog = { color: color, weight: weight, name: name, bark: function() { var bark = 'woof!'; if(name == 'fido') { return 'bark'; } else { return 'meow'; } } }; alert(dog.color); alert(dog.weight); alert(dog.name); alert(dog.bark()); A comparison would be all the built in methods that javascr
  11. Did you get this to work, it seems your post is more of a solution than a question? I also ran across this and noticed numbers was not a parameter of the function and wondered where it came from. Let me know if you still have any issues with it though.
  12. var U = { $: function(id) { 'use strict'; if(typeof id = 'string') { return document.getElementById(id); } // end of typeof } // end of $() function } // end U object This is a rather simple question. The text says the $() function is a property of U, isn't this function technically a method and not a property? Thanks, Mark
  13. function sortWords(max) { // Function block } Why does this function require a parameter of "max"? The argument passed here isn't used anywhere in the function body? Thanks, Mark
  14. ya no offense taken. the task.value=""; works outside the loop, thanks for the warning. As for the join() method, it simply doesn't make sense to use this approach inside the loops as you noted before. So I'll leave it as is. Thanks!
  15. Hartley, Since you may not have the book handy, here's the entire script for your reference: var tasks = []; function addTask() { 'use strict'; var task = document.getElementById('task'); var output = document.getElementById('output'); var message = ''; if (task.value) { tasks.push(task.value); message = '<h2>To-Do</h2><ol><li>'; for (var i = 0, count = tasks.length; i < count; i++) { message += tasks.join('<li><li>');
  16. Hi placid, I was stuck where you were at and tried the below, finally got it to work. var randomNumber = tasks.length; var randomTask = parseInt(Math.random() * randomNumber, 10) + ''; message += '<li>Random Task:' + tasks[randomTask] + '</li>'; Is this similar to yours? Also have you figured out how to modify the script so that the join() function is used to create the final message (instead of concatenating them)? message = '<h2>To-Do</h2><ol><li>'; for (var i = 0, count = tasks.length; i < count; i++) { message += tasks.
  17. I got confused with what you're saying here at first, with you should never add an array to a variable with +=. But I'm assuming you mean its okay to add an array to a variable (using the += operator) if we are looping through an array. I'm glad you read my mind here, the route of having no choice to access all individual values is where I was getting at. The nested loop is absolutely required. Not embarassed at all, thanks for your time. Always a pleasure.
  18. Thanks Hartley, you've pointed out a lot of things to learn from. I am really just trying to understand the difference in storing array values with php and javascript. As I have tested with a simple array (no longer the multidimensional for simplicity sake), I finally grasp the concept now. In PHP: <?php $terran = array('marine', 'marauder', 'reaper'); for ($i = 0; $i < 3; $i++) { echo $terran[$i]; } ?> In Javascript: function process() { 'use strict'; var message = ''; var message2 = ''; var terran = ['marine', 'marauder', 'reaper']; var
  19. major sc2 fan, looking forward to heart of swarm. I might of gotten confused with how php arrays are handled, although there are some major differences between php(which I have yet to figure out) and javascript, I took a chance and used similar syntax. in PHP a similar loop would have been fine wouldn't it? See below: echo $message = terran[$i]; in javascript, concatenation is handled a little different as you mentioned the first value is overriden by the second value. But as you advised, below works now: message += terran[i];
  20. I was working on a simple for loop to emulate the the given example on page 201, the labeled box "MULTIDIMENSIONAL ARRAYS". The example actually shows how to loop through the subarray, but instead I just wanted to loop through the top level array for simplicity. Here is a similar example but with different values in the array: function process() { 'use strict'; var message = ''; var terran = [['marine', 'marauder', 'reaper'], ['battlecruiser', 'banshee', 'raven']]; var output = document.getElementById('output'); for (var i = 0, count1 = terra
×
×
  • Create New...