Jump to content

ShadowMage

Members
  • Posts

    3,476
  • Joined

  • Last visited

Everything posted by ShadowMage

  1. As mentioned before, I haven't actually created an XML file yet. I'm just loading a string previously generated in the PHP into DOMDocument. I did try re-saving all my PHP files as UTF-8, but it didn't seem to make any difference... I also noticed that when I actually save the XML file to the filesystem, it doesn't put anything in the place where the trademark is supposed to be. No trademark, no other goofy symbols. When I output it to the browser, I get the behavior described above.
  2. ok, so I tried escaping the ampersand (™) which doesn't give me an error, but it doesn't print the trademark symbol either. Just prints "™" Also tried using utf8_encode on the xml string before loading it into DOMDocument. I tried it with the chr() function and it gave me the same result as using did before (ie, the goofy 'A' symbol). Using still gives me the same result. Tried it with the actual TM character and it gave me a lot more goofy symbols than before. Didn't get any errors using utf8_encode, though!
  3. I have the xml DTD included in the string I'm trying to load: <?xml version='1.0' encoding='UTF-8'?> I also tried specifying the encoding when I created the DOMDocument object: $doc = new DOMDocument('1.0', 'UTF-8'); which didn't help. I'm not working with any files yet. It just generates the string, then attempts to load it into DOMDocument. Or are you referring to the PHP script itself being saved as UTF-8? As for utf8_encode, where do I use that? On the string I'm trying to load into DOMDocument? Like this: $doc->loadXML(utf8_encode($xml)); Thanks, I didn't know that was possible. If I can't get this working any other way, I'll try creating my own entity.
  4. I'm using DOMDocument to load an xml document from a string generated in PHP. One particular node needs to have a trademark symbol in it's value and I'm having trouble getting that to load with DOMDocument. First a little setup/background: I have a value stored in a database field that needs to have the trademark. This value is both displayed on screen and written to the XML. Right now I'm using placeholder text ("{TM}") and using str_replace to replace the placeholder text with the HTML entity (™) to display it onscreen. This works fine. It doesn't work when writing to XML because the ™ is not a recognized entity apparently. So, when writing to the XML I tried: $systemDesc = str_replace('{TM}', '', $arrGlazeType[$this->GlazeType]['Description']); Which sort of works. I get an extra goofy 'A' symbol, though: Guardian 275™ If I just replace the placeholder with an empty string, it displays just "Guardian 275" as I'd expect. So I tried: $systemDesc = str_replace('{TM}', '™', $arrGlazeType[$this->GlazeType]['Description']); which gives me: Guardian 275â„¢ and $systemDesc = str_replace('{TM}', chr(153), $arrGlazeType[$this->GlazeType]['Description']); which produces an error: Warning: DOMDocument::loadXML() [function.DOMDocument-loadXML]: Input is not proper UTF-8, indicate encoding ! Bytes: 0x99 0x3C 0x2F 0x73 in Entity, line: 19 Line 19 is where the trademark symbol should appear. You might ask "well, why are you using the placeholder anyway?" Good question. When I put the trademark symbol directly into the database, it showed up on screen as a black diamond with a question mark. The htmlentities() function didn't help. And in the XML, I get the same error as using the chr() function. I didn't think this would be that hard...
  5. It could be done with Canvas, yes, but that's much more complicated than Ingolme's suggestion (using a GIF) and wouldn't work in instances where the user has JavaScript disabled since canvas requires JavaScript to function.
  6. To specifically answer the question about multiple conditions in an if statement, you need to use the Logical Operators here: http://www.w3schools.com/jsref/jsref_operators.asp
  7. Yes, they are the same in terms of structure. The difference is in the evaluation of the criteria in the if statements. I'm not sure how much clearer it can be explained. Like Ingolme said, indentation is important to help you keep track of what code is in each block. If we look at your code (properly indented): var x = "b"; var y = "a"; var z = "c"; if(x==y) { if(x==z) { console.log( "equal"); } else { console.log("not equal"); } } Everything between the red brackets is one block of code and will be executed together. So when it checks the condition if(x==y) it will run that code only if x is equal to y and since they're not ("b" is not equal to "a") and you have no else statement to match that block, nothing gets executed. Your other example can be formatted exactly as above, but the condition is different. In that one, the condition evaluates to true (after all, 40 is indeed less than 70) and so the code in the block is then executed. If you change the value of temp to anything greater than 70, you will get the same result as in your first code (that is, nothing). In order to get output under every single instance, you would need to add another else block to go with the first if statement: if(x==y) { if(x==z) { console.log( "equal"); } else { console.log("not equal"); } } else { console.log("not equal"); }
  8. Aren't those technically the same since innerHTML is part of the DOM?
  9. I've actually used it a couple times. One such example: I have a table of values that changes depending on parameters set elsewhere in the page. I use AJAX to send the parameters to PHP and calculate the values then send those values back as a JSON object. I loop through the rows of values like a normal numeric array. I then loop through the "properites" (ie, columns) of each row and update the values in the table.
  10. I just reread the error message, and I misunderstood the message you got. I see now that it says it cannot access the function as a property of the opening (parent) window. JavaScript doesn't work cross-domain (for example, from www.website1.com to www.website2.com). I suspect that the blank URL in your window.open command is making JavaScript think it's going cross-domain. You might need to create a blank page within your site and use that URL in your open command.
  11. What browser are you using and where are you running this script from? Some browsers block AJAX on the local filesystem. I don't remember which ones for sure, but I think IE is one of them. EDIT: Try doing just a simple alert instead of sending the AJAX request. That will confirm whether the code is working or not.
  12. You can also access properties using square brackets like an array index: ObjectName["aaaa"] = "orange"; ObjectName["bbb"] = "green"; There probably aren't many cases where this would be useful or preferred over dot syntax, but there are a few... EDIT: One simple example would be if you needed to loop through all the properties of an object: for (propertyName in ObjectName) { ObjectName[propertyName] = "yellow"; }
  13. If the code does not perform as it is expected there is an error in the code. Not all errors produce error messages. Only syntax errors produce messages. Logic errors simply produce unexpected results. The latter is much more difficult to trace and fix. I don't see anywhere in your code where you check whether a new or used item is selected. You're just passing both prices into the session variable.
  14. One more thing to consider is AJAX won't work if a user has JavaScript disabled. If you do decide to use AJAX, you need to have a good fallback in place.
  15. ShadowMage

    Reg Exp

    I was going to say you could use eval on the string to turn it into a regexp, but that probably wouldn't be a good idea to use on a user input field.
  16. I think this is your answer. I used FireFox to test it and it worked fine. Didn't test in any other browsers though.
  17. What exactly isn't working? Worked when I tried it. The two files need to be in the same folder.
  18. Yes, but to do it efficiently you'd still need to learn a server side language. That way you can have one file with the menu bar in it and just include it on the rest of the pages. Otherwise, you'll need to maintain the same code (the menu) across every single page that uses the menu. JavaScript is the language, it is not a collection of languages. You could skip JavaScript and do something like what davej suggested above and use server-side includes. This is much easier than using AJAX, though maybe not quite as fancy. Plus, server side includes will work even with JavaScript disabled (AJAX will not).
  19. Background-clip is used to specify what area of the element will show the background. When set to content-box, for example, the background will only appear in the content-box of that element. If there is padding on the element, the padding will not have a background. By default, this value is set to border-box, meaning the background will extend all the way to the edge of the border. Background-origin is used to specify what part of the background to show in the element. This is used when the image is larger than the element. It is useful for such situations as creating different states of a button (ie, normal vs hover). You could have an image twice the height of the button with both states on it and use the background-origin to determine which state to show. Background-clip limits the area of the element to have a background, while background-origin limits the area of an image to use as a background.
  20. Although it's pretty new, there is a box-sizing property that specifies how width and height are measured. Set to border-box, it will include padding and border, but not margin. Margin is still separate.
  21. Yeah, tables shouldn't be used for layouts. They end up being a nightmare to modify... The image you posted looks like you could use divs and spans to accomplish the desired look. Would be more flexible and easier to adjust as well. As to the issue at hand, just specify a width and the default behavior is for text to wrap and allow the element to grow in height. You could use min/max width if you wanted to allow some variance in width.
  22. You didn't get a syntax error because there was no syntax error. The syntax is perfectly valid (although useless). The effect of putting that semicolon there was the creation of an empty if statement. What you had is the equivalent to this: if(heading == 'false') { } heading = setDir(e);
  23. So I found out what's causing this. It's actually pretty stupid on my part. There are multiple copies of these popup divs. They use the same form elements but contain different information. I took care of the unique ID issue by appending a "set ID" number to the IDs of all the elements. What I forgot to take into account was that radio buttons form into groups when they have the same name which is good and how they are supposed to work. I had to give them the "set ID" treatment that I gave the element IDs. Now everything works just fine. I can't believe it took me as long as it did to figure this out...
  24. Noticed something interesting. Not sure if I can explain properly, but here goes: First, a little bit of setup information. I mentioned before that these radios are contained in a div used as a popup tooltip. These tooltips are triggered by hovering over the items in a list (not a list element, they're actually in a table so the element is actually a td) and using the mouseover/mouseout events. Clicking on an item brings up a separate div, the contents of which are retrieved via AJAX depending on which item in the list was clicked. I can make changes to the information and save it back to the database, again via AJAX. The AJAX request then sends back a new HTML string which is used to replace the popup tooltip div for the item I just edited. What I've noticed, is that only the last edited item is showing the radio buttons being checked. All other popups have their radios unchecked, even though in the HTML it shows the checked attribute like in the image I posted. This is true even after reloading the page, clearing cache and reloading, even closing the browser and reopening.
  25. Hi dsonesuk, it's been a while. The box appears this way when it is first loaded. There are several sets of buttons like this, some of them appear correctly some don't. There is no JavaScript involved at this point. At least, not involving the radio buttons. These radio buttons are contained in a div that I'm using as a popup tooltip, so JavaScript is used to show/hide that tooltip but that's it. EDIT: Not sure if it was clear in the OP, but the boxes are not checked when displaying on the screen either. It isn't just the DOM window that I'm asking about.
×
×
  • Create New...