Jump to content
Larry Ullman's Book Forums

Paul_808

Members
  • Posts

    25
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Paul_808

  1. What you're saying all seems right to me except that the question specifically says "complete the go back link functionality so that it's accomplished in a progressively enhanced manner, similar to how the print functionality was created." I can't find the connection between the two. And the back button is created in a progressively enhanced manor having a fallback if Javascript is disabled. If this one is a tricky one for you to don't worry about it. I'm going to skip this one. I'm sure I'll have another question soon enough, Thanks!
  2. Chapter 9 #12 asks the reader to complete the go back link functionality so that it's accomplished in a progressively enhanced manner, similar to how the print functionality was created. I have spent about an hour and a half trying to figure out what this question is asking me to do. I believe the book is referencing the go back link on pg 327. Here is the code mentioned (I added return false; because what was in the book didn't work): <body> Please <a href="actualpage.html" id="backLink">go back</a> <script type="text/javascript"> document.getElementById('backLink').onclick = function(){ window.history.back(); return false; } </script> </body> The print button is added to the page only if the print functionality exists. Since the go back function works in all browsers I don't see any connection with the print functionality and the back link. Perhaps there is another way the print button is progressively enhanced? Any insight would be very much appreciated. Thanks!
  3. Awesome. Again very helpful. Thanks so much!
  4. Thanks so much Hartley. That was extremely helpful. The reason I just used the textContent property is because I am just testing this particular exercise in Firefox. This problem was just a learning exercise for me. I'm a bit confused about when and when not to use semicolons. I've probably already read this in the book but are there any rules you recommend I memorize. Thanks again!
  5. Hi, I am trying to create a page - page A, with a link that opens a popup window - page B. Page B will start with a number of 0 being displayed. On page A will be an additional link that will add 5 to the value in page B. The code I have created in an effort to accomplish this is below. The function on page B is not being called and I am not sure what I am doing wrong. Any help would be greatly appreciated. Thanks! Page A contains the following Javascript: window.onload = function(){ var link = document.getElementById('link').onclick = createPopup; } function createPopup(){ var popup = window.open('ex_new_alert.html','PopUp','height=100,width=100'); return false; document.getElementById('addLink').onclick = function(){ popup.window.addToNumber(5); return false; } }; Page B contains the following Javascript: var number = 0; var calc = document.getElementById('calc'); calc.textContent = number; function addToNumber(num){ number += num; calc.textContent = number; console.log(number); };
  6. I found another problem with this demo. If loaded in explorer or chrome many times the page loads expanded for a few seconds before the JS kicks in. I may just have to find a different solution all together.
  7. I need to create an accordion style page using Javascript for a site I'm currently working on. I found an example online that I think is going to work great for me. Unfortunately, I do think there may be a few issues with the scripts used. First there is no onload command and I think there should be. Second, I think the global namespace is going to be polluted with variables. I tried wrapping the one of the scripts in an anonymous function but that broke it. I'm not sure how to correct the issues. Any advice would be greatly appreciated. The example page is here: http://multimediadesignersite.com/test_accordion.html Thanks!
  8. Thank you very much guys. Your feedback was very helpful. The answers brought up a new question which is the difference between functions and methods. I thought they where the same. I did a bit of googleing which helped somewhat. I understand that a method is a type of function invoked from an "invocant" (generally an object or a class) but I am having a hard time visualizing what that actually means. I wonder if you could show an example of function and a method.
  9. Hello, On pg 260 #6 says to view the global variables. Is this something I can do with Firebug and if so how? When I use Firefox's default debugger it says no variables to display? Also two other questions I have are 1. What's the difference between calling and invoking a function? What's the difference between using or not using parenthesis after calling/invoking a function? 2. Why sometimes when using an element do you need to add .value and other times not? Any advice would be very much appreciated. Thanks!
  10. My array is actually named employees. I forgot to change it when I copied and pasted the code above. Sorry about that. My function is working. What I was doing wrong was trying to send an alert before the object existed in the array. I put the alert in an if statement and it works. Thanks for your advice. Again sorry about the confusion.
  11. So it looks like HartleySan is adding an object with one element to an array: newHires.push(employee.firstName); I would like to add the entire employee object including all of it's elements. I'm thinking I would do that with: newHires.push(employee); When I use alert(employees[0].firstName); it works but when I try alert(employees[1].firstName); I get nothing. Any suggestions?
  12. I'm a bit confused with exactly what this question is asking me to do. I'm looking at the solution above and it does not quite make sense to me. In the code above a new object is created named var employee. This appears to be the only object created. Don't I need to create several objects in order to create an array out of them? Can someone please explain what I am missing. Thanks!
  13. It seems after much agony I have finally got my scripts to work in Explorer. Just changing the encoding under the encoding drop down and saving the file was not enough. I needed to change the default encoding settings (under settings>preferences>new document) to UTF8 without BOM. I tried a bunch of things but I think this was the solution.
  14. The script does not involve any server based code. There have been several scripts giving me issues the last two are chapter 5 random and chapter 6 today. This time the unaltered .js file works in all browsers. As soon as I save it, it no longer works in any version of Explorer. In Notepad++ there is an encoding menu item. I selected convert to UTF-8 and saved the files. They are still not working in Explorer. I also tried to create a new file using Aptana Studio and no luck. I am stumped. Any other suggestions would be very much appreciated. Thank you.
  15. I changed the encoding to UTF8 (with and without BOM), deleted the browsing history and still got the same error. I then downloaded Aptana Studio. I created a new Javascript file in Aptana, copied and pasted the code from the unaltered file and received the same results, works in Firefox and Chrome, error in Explorer. Do you have any other suggestions? Thanks!
  16. Thanks so much for the reply but I'm not sure that's the issue. There is an encoding menu item in Notepad++. Encode in ANSI is selected on both files. Both files are also set to UNIX.
  17. Hello, I'm having a bit of an unusual problem and I've spent hours trying to figure it out with no luck. I downloaded the scripts and then made a copy of them. In going through the exercises I open a sample file with Notepad ++ and delete the code but leave the comments. I then fill in the code after reading the book, Then I compare my script to the original and fix any mistakes I've made. My exercises work in Firefox and Chrome but when I test in Internet Explorer two exercises have not. The Explorer console gives me the following error: SCRIPT1014: Invalid character random.js, line 1 character 1. The script is identical to the original. Here's where it gets really weird, if I put the unaltered script in the js folder it works however even if I copy and paste the content of the unaltered script into the script I was working with I still get the error. I deleted the browsing history, I changed the path, I even restarted my computer and no luck. If anyone has any ideas as to what may be going on here I would appreciate them very much. Thanks! Paul
  18. I got it!! I actually forgot that I could use explode. I was thinking the only way to separate the data was to use fgetcsv(). I'm reading the book again but I am going to try to continue with the next pursue question as well. Thank you so much for your help! <?php // view quote pursue.php //Read the files contents into an array $data = file('txt/quotes.txt'); //count items in array $n = count($data); // Pick a random number $rand = rand(0, ($n - 1)); // Pick random line $line = $data[$rand]; //Separate the data $quoteattribute = explode('|', $line); //Print the data print 'quote: ' . $quoteattribute[0] . '<br />attributed by: ' . $quoteattribute[1]; ?>
  19. I believe I need to use fgetcsv to separate the data from the random line. I don't know how to this: //Read the files contents into an array $data = file('txt/quotes.txt'); //count items in array $n = count($data); // Pick a random item $rand = rand(0, ($n - 1)); // Here is where I get lost. I believe to separate the data I need to use fgetcsv. This requires a file pointer which requires a variable for the file location. I don't know how to use fgetcsv with the $rand array. $file = 'txt/quotes.txt'; $fp = fopen($file, 'rb'); $array = fgetcsv($fp, 2000, '|'); print 'quote: ' . $array[0] . ' attributed by: ' . $array[1];
  20. Okay, I got the file writing and reading the quote and attribute together!! Unfortunately, I'm still not sure how I would display multiple random quote/attribute pairs. Here is what I did to get the files to write and read: write: file_put_contents($file, $_POST['quote'] . '|' . $_POST['attribute'] . PHP_EOL, FILE_APPEND | LOCK_EX); read: $file = 'txt/quotes.txt'; $fp = fopen($file, 'rb'); $array = fgetcsv($fp, 200, '|'); print 'quote: ' . $array[0] . ' attributed by: ' . $array[1];
  21. First off I just want to again say thank you so much for writing back. I can't tell you how much I appreciate it. To answer your question, yes, I created one input field named quote and one named attribute. I made them both sticky. At this point they are writing to the quotes.txt doc on seperate lines. I'm not sure how to get them to be written on the same line or how to read them back as seperate values. <form action="add_quote_pursue.php" method="post"> <textarea name="quote" rows="5" cols="30"><?php if (isset($_POST['quote'])) { print htmlspecialchars($_POST['quote']); } else { print 'Enter your quotation here.';} ?></textarea><br /><br /> <textarea name="attribute" rows="1" cols="30"><?php if (isset($_POST['quote'])) { print htmlspecialchars($_POST['attribute']); } else { print 'Attributed by';} ?></textarea><br /><br /> <input type="submit" name="submit" value="Add This Quote!" /> </form>
  22. Larry, I really appreciate you writing back. I understand conceptually what you are saying but I am still stumped. I've reread the chapter, scaned the book and tried using google for a a more precise answer as to how to implement the solution. If possible, can you spell it out for me or perhaps point me to the chapter where I am going to find the info I need. Thank you very much.
  23. Hello, I am a complete newbie in the programming world. I have enjoyed the book but I really wish it provided guidence with the pursue questions. I find them extremely frustrating and have constantly had to search the forum for help. I am currently stumped on the chpt 11 pursue question where it asks to change add_quote.php to separate the quote and attribute inputs, write them separately to a file and then modify view_quote.php so it displays both pieces of data. I have separated the two quotes but I have no idea how to retrieve them together. I don't see where the book tells me how to do this. Any help would be greatly appreciated. Thank you.
×
×
  • Create New...