Jump to content

Ingolme

Moderator
  • Posts

    14,901
  • Joined

  • Last visited

  • Days Won

    177

Everything posted by Ingolme

  1. Javascript doesn't see forms or inputs, all it sees is HTML elements with their properties and methods, you can access HTML elements by their ID or you can use other ways to navigate, like getElementsByTagName(), childNodes and nextSibling. You have to search for the element and extract data from their properties. Add an event listener to something. For example, onchange to the <select> element or onsubmit to the form. Then you use the selectedIndex property of the <select> element to determine which of the options has been selected. For example: function handleEvent(e) { // A reference to the <select> element var select = document.getElementById("mySelectElement"); // A number indicating which <option> element is selected var index = select.selectedIndex; // A reference to the option element that is selected var option = select.options[index]; // Do whatever you want to with the value of the option alert(option.value);}
  2. The closures aren't necessary. There's the this keyword and also the target property of the event object to refer to the element. It would also save memory to have all of the elements refer to the same function. Have you thought about the need to remove the active class from any elements?. This is slightly better: for (i=0; i<_fsMenuItems.length; i++) { _fsMenuItems[i].onclick = makeActive;}function makeActive() { this.className += ' active';}
  3. You shouldn't need to use try and catch for your own error handling. Just set the var $err without throwing exceptions and use your switch() like usual. Save the try-catch for real exceptiond thrown by PHP classes, like this particular case that you're having right now. // At the beginning of your document$err = 0; // Initialize the error code variable//// . . .//// Checking for exceptions thrown by PDO.try { $stmt->execute();} catch (PDOException $e) { $errorInfo = $stmt->errorInfo(); if($errorInfo[0] == '23000') { // 23000 is the error code for duplicate key $err = 2; } else if($errorInfo != '00000') { // There's some other error that's not a duplicate key $err = 3; }}//// . . .//// Later on:if($err) { // Any number but 0 evaluates to true switch($err) { // All your error codes in here }}
  4. Like I said earlier, test the code outside of the try-catch block.
  5. Can you show all the code on your page? Wrap your code in [code] tags
  6. If you're still using a try-catch block I suggest removing it for now.
  7. var_dump() actually doesn't return a value, it outputs the data without the need for an echo statement, so remove the echo part. The reason we're using var_dump() at the moment is to determine what the problem is. var_dump() gives a lot of information about what's contained in a variable, it never outputs nothing.
  8. By no error what do you mean? Do you mean that the error code is 00000? When it doesn't work, what is being displayed by var_dump()?
  9. Does your <form> element have an enctype attribute?
  10. What is the program doing? You should use var_dump($errorInfo) to see what exactly you're getting.
  11. I'd say that the error code is a string, not a number, which means that the exception will always be thrown because the !== operator also does a type check and it's checking for a number. Either use != instead of !==, or test for "00000" instead of 00000
  12. Ingolme

    UTC+0 time set

    Is the user supposed to be the one choosing these values? Is there a form involved?
  13. You need to replace ' and " with ' and ". That will solve the problem. The way you're using document.write is a problem. When document.write is called it tries to correct bad HTML. For example, the string "<option value='" will be transformed into "<option value></option>". To fix this, build the entire string first, then call document.write() just once. Putting it all together: var value;var str = "<select name='player'>";for (i = 0; i < x.length; i++) { str += "<option value='"; value = document.write(x[i].getElementsByTagName("Name")[0].childNodes[0].nodeValue); value.replace(/'/g, "'"); value.replace(/"/g, """); str += value; str += "'>"; str += "</option>";}str += "</select>";// Write the string to the documentdocument.write(str); As a footnote, document.write() will cause your page to be completely erased and written over if it's called after the page has finished loading (for example, if you have it inside an event handler). To be safe, add HTML to the document by changing the innerHTML of an element instead of using document.write()
  14. Ingolme

    UTC+0 time set

    You can get a timestamp using the gmmktime() function. Otherwise, I don't know exactly what format you want the time to be in.
  15. I see. Which script is populating the list? I believe that it's creating code that might look like this: <select> <option value='apostrophe's problem'>apostrophe's problem</option> ...</select>
  16. If you want to load new data from the server you'll need to learn AJAX. You made a mistake in your HTML, the element is <select>, not <selection>. Once you've corrected that, you can use Javascript to assign the onchange event handler which will make an AJAX call. When you pass data from a PHP variable to a Javascript string, make sure to escape quotation marks using addslashes: var test = "<?php echo addslashes($test); ?>";
  17. Inline elements can have padding and margin, but only the horizontal padding and margin have a visual effect. You can change the element to be an inline-block using the display property. Inline-blocks can have width, height, padding and margin without any problem.
  18. You substitute the angle brackets with HTML entities, which are explained right there in the tutorial: http://www.w3schools.com/html/html_entities.asp
  19. Your page only consists of an image. Just give a classname to your images and then set max-width to 100% .responsive { max-width: 100%; height: auto;} If you're using Bootstrap then just give the class img-responsive to your images. Bootstrap also has a built in columns system which will adapt to different screen sizes, read about it here: http://getbootstrap.com/css/#grid You should make sure your code is valid if you want it to work properly in all browsers. http://validator.w3.org/check?uri=http%3A%2F%2Fjdsplace.us%2Fmilitary%2Fmm%2Fmm7.html
  20. Probably because your country's firewall is blocking it.
  21. Are you using some intermediate system between the Javascript and the XML file? Javascript on its own shouldn't have a problem with the apostrophes if it's directly reading data from the XML DOM tree.
  22. I don't particularly see that as an imperfection. They had to choose a name for the property and they decided to go with the American spelling, probably because most people involved in the writing of the specification were American.
  23. Ingolme

    images

    Put the HTML file and the image file in the exact same folder right next to each other. Make sure that you know what the extension of the image is. ".jpg" is different than ".JPG", you must use the one that the image file has. Windows often has file extensions hidden by default, you can change that in the folder options.
  24. In CSS, the word "color" is spelled as in American English. So the rule would be background-color.
  25. It's not about the targetOrigin parameter, the postMessage function works fine. The problem is that you're sending the message before the receiving document is listening for it. It looks like Chrome doesn't let you set the onload function because it's being executed in the local filesystem and security features prevent functions from being executed between local files. This works fine on a server environment. page1.html var target = window.open("page2.html");target.onload = function() { target.postMessage("Hello, World!", "*");}; page2.html window.addEventListener("message",function(e){ alert(e.data);},false); This works on the desktop but is not a reliable solution: page1.html var target = window.open("page2.html");setTimeout(function() { target.postMessage("Hello, World!", "*");}, 1000);
×
×
  • Create New...