Jump to content

Ingolme

Moderator
  • Posts

    14,901
  • Joined

  • Last visited

  • Days Won

    177

Everything posted by Ingolme

  1. You can create two Javascript Date() objects for the start time and end time, then subtract the start timestamp from the end timestamp. The result will be a number in milliseconds. Divide by 1000 to get seconds and then by 3600 to get the number of hours. You can use the modulo operator and Math.floor() to get a combination of hours, minutes and seconds.
  2. Ordinary form submission will never be obsolete. It is part of the core of HTML. However, it is really popular to use AJAX as more comfortable alternative on browsers that support Javascript.
  3. This is the sort of project that requires a database, which would require a server-side language. Javascript can't save information on its own. You could have Javascript add elements to the array, but as soon as you leave the page all the information would disappear and at no point would it be available to anybody else but you.
  4. If you want to set percentage widths, use CSS. CSS will override the width and height attributes.
  5. Your translate function is only showing the last element in the array. What's also a problem is that arrays can only have numbers as indices, if you want a string index you must use an object (Object syntax uses curly braces instead of square brackets). I'll simplify your code for you. Here are a few key points: 1. You don't need a word() prototype, you can just create a literal object 2. The switch() parts aren't necessary because you can just check to see if the item exists in the translation object. 3. You need two different objects, one for English and one for Spanish. In each object, the keys represent the language you're translating from and the values represent the language you're translating to. var translation = {};// Spanish dictionarytranslation.spanish = {};translation.spanish["gato"] = "cat";translation.spanish["perro"] = "dog";translation.spanish["hola"] = "hello";// English dictionarytranslation.english = {};translation.english["cat"] = "gato";translation.english["dog"] = "perro";translation.english["hello"] = "hola";// Translate functionfunction translate(language, word){ if(translation[language]) { if(translation[language][word]) { document.getElementById("translation").innerHTML = word + " ~ " + translation[language][word]; } else { alert("I don't know that word."); } } else { alert("There is no language " + language); }}// Prompt the user for a wordfunction spanishWord(){ var word = prompt("Type in Spanish word to receive the translation."); translate("spanish", word);}function englishWord(){ var word = prompt("Type in English word to receive the translation."); translate("english", word);}
  6. Use [CO DE] [ /CODE] tags to show code in your posts. I don't know what you expected this function to do: function translate(word){ for (var key in translation){ translation[key].spanish + translation[key].english; } document.getElementById("translation").innerHTML = str;}You pass a parameter word that is never used. You loop through each item in the translation object, concatenate two of its properties, but then you don't assign the result of that to any variable. At the end of the function you set the innerHTML of an element to the value of str, which is a variable that is not defined inside the function.
  7. It will work in quotes, but if you want to remove the quotes you also have to remove the parentheses, because setTimeout takes a function reference, not the return value of the function.
  8. Watch your typing, this typo would cause the element to not exist at the specified index: photo[itemcountedr]=1; In Javascript you don't need to define the length of the array before using it, but watch out when setting the index of an array. If you create a new array and only set index 5, elements 0, 1, 2, 3 and 4 will exist but with an undefined value. Without seeing your actual code I can't tell where the problem is. It has nothing to do with what number you use for the index, it's most likely that due to a mistake, you didn't create element 42.
  9. If you really want to get into the details, Wikipedia has an extensive description of what a framework is: http://en.wikipedia.org/wiki/Software_framework
  10. That's right. Everything about the appearance of an element can be changed using CSS.
  11. I'm not sure what you're referring to.
  12. And Image() should have an uppercase I.
  13. Perhaps their description is not perfect. By default, most elements show variable-width fonts. But elements such as <kbd>, <samp> and <code> use monospace fonts by default. This can be changed with CSS.
  14. You can't pass the elements as parameters to the function, but you can access them using getElementById(). This function should work: function drawShape(){ // get the canvas element using the DOM var canvas = document.getElementById('mycanvas'); // Make sure we don't execute when canvas isn't supported if (canvas.getContext){ // use getContext to use the canvas for drawing var ctx = canvas.getContext('2d'); var dieX = Number(document.getElementById("dieX").value); var dieY = Number(document.getElementById("dieY").value); var edgeLoss = 5; var waferSize = 200; // Draw Wafer ctx.beginPath(); ctx.arc(220,220,waferSize,0,Math.PI*2,true); // Outer Edge ctx.arc(220,220,(waferSize-edgeLoss),0,Math.PI*2,true); // Good die edge ctx.stroke(); // Draw Dies ctx.beginPath(); // Added this line for (var x = 1; x < 450; x += dieX) { ctx.moveTo(x, 0); ctx.lineTo(x, 440); } for (var y = 1; y < 450; y += dieY) { ctx.moveTo(0, y); ctx.lineTo(440, y); } ctx.strokeStyle = "#a9a9a9"; ctx.stroke(); } else { alert('You need Safari or Firefox 1.5+ to see this demo.'); }}
  15. A framework could be considered a type of library. The difference between a framework and a library is that the framework gives you a system ontop of which you build your program, while the library is a set of properties and functions you can use to do a particular task. As for your second question, that suggestion is in the guidelines because the spam filter is likely to mark you as a spammer if you sign up with an address such as person@xyds.com.
  16. I don't know exactly what you're trying to do, so I can't tell you what's correct or not.
  17. In your jsfiddle example the image hasn't loaded. Applying padding directly on the img element should put space between it and the text but you need an image to actually load to test it.
  18. What do you mean with "break javascript string text"? Do you mean a line break? If you're outputting this to HTML, you need to use a <br> element. If this is in the console or an alert() box, then n is enough.
  19. Ingolme

    update images

    If $_POST['up'] is an array then you can't use strlen() on it. It looks like $i is 1 and there's no element 1 in the $_POST['up'] array. Where is $i being set?
  20. It seems you don't know how to retrieve data from forms in PHP. Here's a tutorial page about it: http://www.w3schools.com/php/php_forms.asp In your SQL queries you're sending the literal string 'list1' and 'list2', the id= part will probably cause a MySQL error because of bad syntax.
  21. In your last declaration you're missing a direction: background-image: linear-gradient(#ffffff, #4e6d04); You also need to use the word "to" if you want to specify the direction verbally: "to top" rather than just "top". So your code should look like this: background-image: -webkit-linear-gradient(to top, #ffffff, #4e6d04);background-image: -moz-linear-gradient(to top, #ffffff, #4e6d04);background-image: -o-linear-gradient(to top, #ffffff, #4e6d04);background-image: linear-gradient(to top, #ffffff, #4e6d04);
  22. Decrease the number by which you're changing amount3. Instead of amount3 += 0.2 try amount3 += 0.05
  23. It looks like in your loop, x += dieX is actually doing a string operation. First x is "1", then it's "15" and then it's "155". To solve this, case dieX and dieY to numbers when you get their value from the field. var dieX = Number(document.getElementById("dieX").value);var dieY = Number(document.getElementById("dieY").value); You probably should have a button to activate the drawing function.
  24. If you're not familiar with PHP, you should read the tutorial. Once you know PHP, you can go through the contents of a directory using scandir() and read files using fopen() and fread(). You can load all the content of a file at once using file_get_contents(), but if you just need to read the first few bytes of the file then fread() is much more efficient.
  25. Something in your stylesheet must be hiding the border for small mobile devices. Either that, or the browser automatically chooses not to display the border on small screens.
×
×
  • Create New...