Jump to content
Larry Ullman's Book Forums

Max

Members
  • Posts

    112
  • Joined

  • Last visited

Everything posted by Max

  1. The web site I got the code from is http://www.google.es/. On another subject, I find Google quite irritating as it assumes, as I am in Spain, that I want to do a Spanish search. I can call www.google.com, www.google.co.uk, or whatever but it still reverts to Spanish searches. Even going into advanced search mode doesn't really fix it, so if I am looking solely for British sites, I use www.yahoo.co.uk. I will not comment on the press story today!!!........ http://www.dailymail.co.uk/debate/index.html
  2. Thanks for that. In future I will use <!doctype html> and be more disciplined when it comes to using symbols.
  3. Larry says in his book that not using 'head' creeps him out. I have to say that <!doctype html> is doing the same to me. Firstly, it is highlighted red in my text editor (SciTE). Secondly, what does an old (e.g. 2010) browser do with it?....treat it as strict? Transitional? Can it handle frames? Will it go into quirks mode? Thirdly, when using this with utf-8 a number character (as in Nº) became a smiley face on my website. I've now changed it to 'N°' I think I understand what the old coding did (e.g. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">) ...that it was telling the browser how to interpret the html from the server in a certain way and I was sort of comfortable with that, but the new one seems too SHORT!
  4. Yes, I am sure that Google know what they are doing (well....they have a lot more money than me!...so must be getting something right). On the subject of server generated code, I would suggest that the Google server is generating the JS (as we would in php) as the list of strings that appear on the entry of characters must change (I guess) with the statistics of searches. i.e. if lots of people are looking up 'euro crisis' then the characters e - u would bring that up from JS. Just guessing here.
  5. Thanks...but that begs two questions - 1: Is there a 'maxifier'? to bring it back. 2: Included in the code (not shown in my example) is CSS and JS and as far as I know other scripts embedded in the HTML. Far beit for me to tell Google how to do their jobs but............they DO make Chrome! Wouldn't it be easier (and industry compliant) if they followed the first chapters of Larry's book and put the CSS and JS in separate files????
  6. Anothe philosophical question for Larry and all wiser and more knowledgable than I.... I took Larry's advice and had a look at Google's front page to see how they used JS to autocomplete the search criteria - you know, when you put 'AA' in the search window - before pressing the search button, it gives you 'aaron', 'aaliyah' etc. but oddly, not Aardvaark! but I digress. What I got was a huge block of compressed code that was obviously generated by a server side language. Here is a SMALL section: function ob(a,{var c=jb,d=lb,g;g=34>=a?a<=Z.w?a==Z.u||a==Z.v||a==Z.z?i:e:a>=Z.k&&a<=Z.o?e:i:200<=a?e:i;g&&(c=kb,d=mb);if(d){d=encodeURIComponent;c=["//www.google.com/gen_204?atyp=i&zx=",(new Date).getTime(),"&oge=",a,"&ogex=",d("37102"),"&ogf=",j.bv.f,"&ogp=",d("1"),"&ogsr=",Math.round(1/c),"&ogv=",d("1337744543.1337808325"),"&ogd=",d("es"),"&ogl=",d("es")];if({"ogw"in b&&(c.push("&ogw="+b.ogw),delete b.ogw);var f;g=b;var h=[];for(f in g)0!=h.length&&h.push(","),h.push(f),h.push("."),h.push(g[f]);f=h.join("");""!=f&&(c.push("&ogad="),c.push(d(f)))}sa(c.join(""))}}I=ob;n("il",I,J);var pb={};r.il=pb;var qb=function(a,b,c,d,g,f,h,m,k,q){v(function(){j.paa(a,b,c,d,g,f,h,m,k,q)})},rb=function(){v(function(){j.prm()})},sb=function(a){v(function(){j.spn(a)})},tb=function(a){v(function(){j.sps(a)})},ub=function(a){v(function(){j.spp(a)})},vb={"27":"//ssl.gstatic.com/gb/images/silhouette_27.png","27":"//ssl.gstatic.com/gb/images/silhouette_27.png","27":"//ssl.gstatic.com/gb/images/silhouette_27.png"},wb=function(a){return(a=vb[a])||"//ssl.gstatic.com/gb/images/silhouette_27.png"},xb=function(){v(function(){j.spd()})};n("spn",sb);n("spp",ub);n("sps",tb);n("spd",xb);n("paa",qb);n("prm",rb);Ta("gbd4",rb);if(l.a("")){var yb={g:l.a(""),d:l.a(""),e:"",sanw:l.a(""),m:"",p:"//ssl.gstatic.com/gb/images/silhouette_96.png",xp:l.a("1"),mg:"%1$s (delegada)",md:"%1$s (predeterminada)",mh:"276",s:"1",pp:wb,ppl:l.a(""),ppa:l.a("1"),ppm:"Página de Google+"};r.prf=yb};if(l.a("1")&&l.a("1")){var $=function(a){Y(function(){u("pw",a);A("pw")})};n("lPW",$);s.push(["pw", The question is - is the future of JS that it will all one day be generated by a WYSIWYG processor that will take all of the fun out of coding???
  7. Yes - and in Spain you have two surnames, so that Spanish web sites inputs are: Forename: First surname Second Surname I can't think of any way of reliably splitting one string into forename(s) and surname(s)
  8. Hi As a newbie, I'm not entirely sure what the purpose of this line is: formattedMiddle = fullName.slice(6,11); Presumably you want to extract the middle name from the string, but how do you know that it starts at 6 and is 11 characters? What if there are two middle names?
  9. Thanks One thing I found recently is that I had left phpinfo.php on the website which, if anyone wished, would have been accessible. In truth, I don't think anyone would be interested in my websites as none of them hold client details of any import. I have removed it now though!
  10. Oh...and Monkey Island. Edward - you lucky chap - being able to spend all day with php!
  11. Hi Paul Thanks for that - it's comforting to know that W3 and I came to more or less the same code, especially when I am having so much trouble absorbing all of the concepts in the book. (being 55 doesn't help). Am on the third pass!!! If it weren't for Larry's great writing style I would have given up by now. Hi HartleySan Yes..Alone in the Dark, Indiana Jones, Noctropolis - all great games. Don't have time nowadays, unfortunately!
  12. Hi In both php and javascript books, you set the home page as a php script e.g. index.php. This begs the question whether a search engine such as Google will find the page / web site as easily as 'index.html'. In the past, I have always made the homepage 'index.html' and then called the .php files from the nav bar (e.g. aboutus.php). Your views would be appreciated. Max
  13. Hi A somewhat philosophical question here regarding web security. On pages 229 and 489 you show a schematic whereby the php scripts are in a subdirectory of the webpage. Wouldn't it be more secure to put the 'includes' directory in the same place as 'mysql.connect.php' and call it with ../includes/script.php? This would make it a little harder for malicious people to access programs from their browser. ...just a thought....
  14. Hi there Thanks for all your help, Edward and HartleySan. I think I have it now...... //Give the whole date string to variable 'today' var today = new Date(); //find out if there is only one digit (i.e. 0 - 9) if (today.getMinutes() < 10) { //create a variable (todayMinutes) to accept the number of minutes from 'today' var todayMinutes = '0' + today.getMinutes(); } else //if there are 2 digits, don't do anything except pass the Nº minutes to 'todayMinutes' { var todayMinutes = today.getMinutes(); } //Now todayMinutes is a variable (integer?..string?) between 00 and 59 // Create a custom message: var message = 'Right now it is ' + today.toLocaleDateString(); //add the minutes variable to the text... message += ' at ' + today.getHours() + ':' + todayMinutes; // Get a reference to the paragraph: var output = document.getElementById('output'); -------------------- However, this still leaves us with a problem.... without adding the zero to minutes (commenting out if/else and replacing it with 'var todayMinutes = today.getMinutes();'), the result is:.... 'Right now it is 05 May 2012 at 3:8'..... ...and the variable 'today' equals 'Sat May 05 2012 03:02:47 GMT+0200 (Hora de verano romance)'. You will notice that the day, hour and minute are all preceded by a zero which suggests that js is converting the days as text and the hours and minutes as a numeric, otherwise 'today' would be 'Sat May 5 2012 3:2:47 GMT+0200 (Hora de verano romance)'. O.K., the script works, but I would like to know why single days are passed to a variable with a preceding zero and hours and minutes aren't. I have tried the following - it works but still doesn't supply the zero on the single digit minutes:..... var todayMinutes = today.getMinutes().toString(); //Instead of the if/else conditional. but still get:......Right now it is 05 May 2012 at 3:1 I know that this all may seem abstruse, but I feel that I'm missing something here. By the way, Edward, your Avatar has brought back happy memories of playing Alone in the dark!!
  15. O.K. - stuck again! Page 178 - chapter 6. As a learning tool, I decided to edit 'today.js' so that when it displayed single digit minutes ((i.e. 0 - 9) it would insert a zero by way of formatting. I have created a new variable 'todayMinutes' to which I add a zero if the number of minutes are less than ten. The only problem is that it doesn't work! I have substituted the zero for a text character to force the variable to a string without success. Would appreciate some advice:............... // today.js // This script indicates the current date and time. // Call this function when the page has loaded: function init() { // Want to be strict: 'use strict'; // Create a Date object: var today = new Date(); if (today.getMinutes() < 10) { var todayMinutes = '0' + today.getMinutes(); } // Create a custom message: var message = 'Right now it is ' + today.toLocaleDateString(); message += ' at ' + today.getHours() + ':' + todayMinutes.value; // Get a reference to the paragraph: var output = document.getElementById('output'); // Update the innerText or textContent property of the paragraph: if (output.textContent !== undefined) { output.textContent = message; } else { output.innerText = message; } } // End of init() function. window.onload = init;
  16. Hi HartleySan Many thanks - I came to the same conclusion by reading the book again vis:.... Hi Larry I think that I have resolved it. I think it is because when you assign 'tofixed(n)' to a variable it becomes a string (1st para, page 154). If I change:....... // Display the total: document.getElementById('total').value = total.toFixed(2); ...to:..... // Display the total: document.getElementById('total').value = total; ....then it works! Again, many thanks Max
  17. Hi Larry 'With total = total.toFixed(2);' included in the script, the results (irrespective of what you enter) are: Quantity: 1 Price per unit: 1.00 Tax Rate (%): 0.0 Discount (%): 0.00 Total: 0.00 It does this in IE8, Chrome and Firefox 11. I have attached the actual js file for you to try. Best regards Max shopping1.js:...... // Script 4.2 - shopping.js // This script calculates an order total. // Function called when the form is submitted. // Function performs the calculation and returns false. function calculate() { 'use strict'; // For storing the order total: var total; // Get references to the form values: var quantity = document.getElementById('quantity').value; var price = document.getElementById('price').value; var tax = document.getElementById('tax').value; var discount = document.getElementById('discount').value; // Add validation here later! // Calculate the initial total: total = quantity * price; //Calculate the discount: discount /= 100; // Factor in the discount: total = total - (total * discount); // Make the tax rate easier to use: tax /= 100; tax++; // Factor in the tax: total *= tax; // Format the total: total = total * 1; total = total.toFixed(2); // Display the total: document.getElementById('total').value = total.toFixed(2); // Return false to prevent submission: return false; } // End of calculate() function. // Function called when the window has been loaded. // Function needs to add an event listener to the form. function init() { 'use strict'; // Add an event listener to the form: var theForm = document.getElementById('theForm'); theForm.onsubmit = calculate; } // End of init() function. // Assign an event listener to the window's load event: window.onload = init;
  18. Hi there Sorry - but another problem with shopping1.js! As a learning process, I decided to mess about with the script so that the discount can be expressed as a percentage instead of an amount. All works well except that if I put in the following line (marked with asterisks below) the script crashes, by which I mean that js just fills the windows with zeros:.... total = total.toFixed(2); I even included the line 'total = total * 1' in case js was looking at total as a string variable but it still crashes. The command 'document.getElementById('total').value = total.toFixed(2)' works fine. Totally baffled!!!!! ------------------------------------------------------------------------------------------- // Script 4.2 - shopping.js // This script calculates an order total. // Function called when the form is submitted. // Function performs the calculation and returns false. function calculate() { 'use strict'; // For storing the order total: var total; // Get references to the form values: var quantity = document.getElementById('quantity').value; var price = document.getElementById('price').value; var tax = document.getElementById('tax').value; var discount = document.getElementById('discount').value; // Add validation here later! // Calculate the initial total: total = quantity * price; //Calculate the discount: discount /= 100; // Factor in the discount: total = total - (total * discount); // Make the tax rate easier to use: tax /= 100; tax++; // Factor in the tax: total *= tax; // Format the total: total = total * 1; ****Crashes here:....**** total = total.toFixed(2); // Display the total: ****This works:-----****document.getElementById('total').value = total.toFixed(2); // Return false to prevent submission: return false; } // End of calculate() function. // Function called when the window has been loaded. // Function needs to add an event listener to the form. function init() { 'use strict'; // Add an event listener to the form: var theForm = document.getElementById('theForm'); theForm.onsubmit = calculate; } // End of init() function. // Assign an event listener to the window's load event: window.onload = init; ------------------------------------------------------------------------------------------- Would appreciate an explanation. From confused of Spain.
  19. Hi Paul Many thanks for that - you have cleared it up perfectly.
  20. Hi everyone I am working through the book again and am really having trouble getting my head round the shopping calculator (shopping.html, page 103), so would be grateful if you would review my comments to say if I have understood it correctly:....... *****MY COMMENTS ARE LIKE THIS************* -------------------------------------------------------------------------------------------------------------------------------------- *****THIS IS LARRY'S HTML - 'shopping.html'********* <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Shopping Calculator</title> <!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link rel="stylesheet" href="css/styles.css"> </head> <body> <!-- shopping.html --> *****THE COMMAND '<form action=' WILL SEND AN ARRAY, ON SUBMITTING OF THE FORM, OF THE 5 VARIABLES, EACH WITH ITS VARIABLE NAME (E.G. "quantity, 4") BY METHOD "POST" WHICH WILL BE "INTERCEPTED" BY THE JS SCRIPT********** <form action="" method="post" id="theForm"> <fieldset> <p>Use this form to calculate the order total.</p> <div><label for="quantity">Quantity</label><input type="number" name="quantity" id="quantity" value="1" min="1" required></div> <div><label for="price">Price Per Unit</label><input type="text" name="price" id="price" value="1.00" required></div> <div><label for="tax">Tax Rate (%)</label><input type="text" name="tax" id="tax" value="0.0" required></div> <div><label for="discount">Discount</label><input type="text" name="discount" id="discount" value="0.00" required></div> <div><label for="total">Total</label><input type="text" name="total" id="total" value="0.00"></div> <div><input type="submit" value="Calculate" id="submit"></div> </fieldset> </form> ****NOW CALL THE JAVASCRIPT******** <script src="js/shopping1.js"></script> </body> </html> ******THIS IS NOT THE JS USED BY THE HTML BUT IS ESSENTALLY IDENTICAL EXCEPT WITH MORE OF LARRY'S COMMENTS.************* // Script 4.2 - shopping.js // This script calculates an order total. // Function called when the form is submitted. // Function performs the calculation and returns false. ******THIS STARTS THE FUNCTION THAT WILL BE CALLED AT THE END BY THE VARIABLE 'theForm' (MORE ABOUT THAT LATER).********** function calculate() { 'use strict'; // For storing the order total: ******'total' IS A SIMPLE VARIABLE TO STORE THE DECIMAL NUMBER THAT WILL RESULT FROM THE CALCULATION*********** var total; ******MOVE THE VARIABLES FROM "POST" TO JS*************** // Get references to the form values: var quantity = document.getElementById('quantity').value; var price = document.getElementById('price').value; var tax = document.getElementById('tax').value; var discount = document.getElementById('discount').value; // Add validation here later! // Calculate the initial total: total = quantity * price; // Make the tax rate easier to use: tax /= 100; tax++; // Factor in the tax: total *= tax; // Factor in the discount: total -= discount; // Display the total: document.getElementById('total').value = total; // Return false to prevent submission: return false; } // End of calculate() function. *****NOW WRITE THE LISTENER********* // Function called when the window has been loaded. // Function needs to add an event listener to the form. function init() { 'use strict'; // Add an event listener to the form: *****AND THIS IS WHERE I HAVE A PROBLEM........WHY ARE WE CALLING ALL OF THE DATA AGAIN BY WAY OF 'theForm'? IS 'document.getElementById('theForm')' CALLING THE WHOLE POST ARRAY AND WHY? var theForm = document.getElementById('theForm'); *****CALL THE "calculate" FUNCTION***** theForm.onsubmit = calculate; } // End of init() function. *****THIS CALLS THE "init" FUNCTION WHEN THE WINDOW LOADS****** // Assign an event listener to the window's load event: window.onload = init; --------------------------------------------------------------------------------------------------- The only other possibility that I can think of is that "var theForm = document.getElementById('theForm');" calls an array from POST that includes all of the variables stated above, and then passes them to the "calculate" function as required. To put the question another way, is the variable e.g. "quantity" - the actual number - received directly from POST or secondarily from the array "theForm"? I imagine the variable "the.Form" to look like this: quantity,4 price,45.67 tax,20 discount,10.00 total,0.00 Any comments and advice would be greatly appreciated. Regards Max
  21. Many thanks, HartleySan, It seems obvious now that you have explained it. I am working through the book again from the beginning!!
  22. Hi there HartleySan I seem to have the program working now, and it does all that I want EXCEPT it now leaves all of the subsequent windows (e.g. home, about us) in the same format i.e. with height=500,width=600,top=200,left=200,location=no,resizable=yes,scrollbars=yes. ------------php--------------- START WHILE....... echo '<tr style="background-color: #FFFFFF;" valign="top"><td>' . $findmower2['Ref'] . '</td><td><a href="findmower/' . $findmower2['Ref'] . '.html" id="link" target = "PopUp"> ' . $findmanu2['Manufacturer'] . ' ' . $findmower2['Name'] . '</a></td><td>' . $price . '</td><td>' . $comments . '</td><td align = "center"><img src = "mowerimages/' . $findmower2['Ref'] . '.jpg" alt = "Sorry - no image" title = "' . $findmower2['Name'] . '" height = "100px" /></td></tr>'; ......END WHILE echo '<script src = "popups.js"></script>'; ------------------------------ popups.js is Larry's popups script with a couple of modifications for new window size. // Script 9.5- popups.js // This script creates a popup window on every link. // Function called when the link is clicked. function createPopup(e) { 'use strict'; // Get the event object: if (typeof e == 'undefined') var e = window.event; // Get the event target: var target = e.target || e.srcElement; // Create the window: var popup = window.open(target.href, 'PopUp', 'height=500,width=600,top=200,left=200,location=no,resizable=yes,scrollbars=yes'); // Give the window focus if it's open: if ( (popup !== null) && !popup.closed) { popup.focus(); return false; // Prevent the default behavior. } else { // Allow the default behavior. return true; } } // End of createPopup() function. // Establish functionality on window load: window.onload = function() { 'use strict'; // Add the click handler to each link: for (var i = 0, count = document.links.length; i < count; i++) { document.links.onclick = createPopup; } // End of for loop. }; // End of onload function. ------------------------------------- I am still trying to get my head round your .js script - much of it doesn't seem to be in Larry's book so will have to get on internet when possible to search w3c. Many thanks Max
  23. Hi there HartleySan Many thanks for that - as I am a newbie with js, I am having to work through it slowly to get my head round it! In the meantime, perhaps I can explain it better if I show you the code..... This is the php This is part of a while loop that selects all of the appropriate products from MySql There is a heading for each column and then a listing as follows:.. echo '<tr style="background-color: #FFFFFF;" valign="top"><td>' . $findmower2['Ref'] . '</td><td><a href="' . $findmower2['Ref'] . '.html" target = "_blank">' . $findmanu2['Manufacturer'] . ' ' . $findmower2['Name'] . '</a></td><td>' . $price . '</td><td>' . $comments . '</td><td align = "center"><img src = "mowerimages/' . $findmower2['Ref'] . '.jpg" alt = "Sorry - no image" title = "' . $findmower2['Name'] . '" height = "100px" /></td></tr>'; which continues until...end of while This is the resultant html source code...... <tr style="background-color: #FFFFFF;" valign="top"><td>532</td><td><a href="532.html" target = "_blank">Allen 215</a></td><td>£500</td><td>Test 215</td><td align = "center"><img src = "mowerimages/532.jpg" alt = "Sorry - no image" title = "215" height = "100px" /></td></tr> ...which works great but doesn't allow me to control the size of the emergent window (why doesn't <a...> have a height = "..." width = "..." facility???). One alternative is to insert js....... <tr style="background-color: #FFFFFF;" valign="top"><td>532</td><td><a href="javascript:location='532.html';window.open('532.html','215','height=500,width=500,scrollbars=yes')">Allen 215</a></td><td>£500</td><td>Test 215</td><td align = "center"><img src = "mowerimages/532.jpg" alt = "Sorry - no image" title = "215" height = "100px" /></td></tr> ...but this doesn't open into a new window. I think I need to re-read a whole swathe of the book before I try any more of this. Thanks again.
  24. Hi HartleySan No, I can do that with php, but it seems unnecessary when we have set the URL using <a href=http://URL.com target = "_blank">. What I would like to happen is for html5 to call a js function that sets the window size and position without having to declare the first argument for every product listed. It probably won't make any difference at all to the user, I just would like to make the code more concise. Would just like to comment that I think it is a great book.
×
×
  • Create New...