|
JSON would be better, but any browser's HTML DOM methods will also work with responseXML. Quickie Google search yields: http://www.w3schools.com/Ajax/ajax_responsexml.asp which should serve as a very basic example. EDIT: prototype.js may have some methods as well. I've no experience with prototype myself; I'm extrapolating that based on my experience with jQuery, which has some nice XPath-ish methods. There Will Be Penalty fucked around with this message at 01:31 on Feb 3, 2009 |
# ¿ Feb 3, 2009 01:28 |
|
|
# ¿ May 4, 2024 16:08 |
|
Packet Loss posted:Just the tags - I have a table that I can't access the HTML on, I need to remove just the row tags, so I can have just columns. The W3C HTML standards say you can't just stick a <td> directly inside a <table>. You need a single <tr> to contain all the columns. table.getElementsByTagName("tr") will yield a list of table rows inside the given table. Iterate through each one to get their innerHTML. Concatenate all those values and stick them inside a single <tr> and you will probably be OK. However this is all moot... Packet Loss posted:The table has an ID, but evidently there's an underscore in the ID which I believe is invalid and so my code always fails. Underscores are perfectly fine in an ID: http://www.w3.org/TR/html4/struct/global.html#h-7.5.2 So the problem is something else.
|
# ¿ Feb 4, 2009 23:01 |
|
heeen posted:I read somewhere, that JSON is significantly faster to parse on the client than xml. And the code to access data inside JSON is much shorter. And JSON explicitly distinguishes between arrays and hashes. And you don't have that problem with some XML-to-JavaScript-object parsers where <foo><bar>1</bar><bar>2</bar></foo> and <foo><bar>1</bar></foo> result in different types of JavaScript object structures. There Will Be Penalty fucked around with this message at 23:06 on Feb 4, 2009 |
# ¿ Feb 4, 2009 23:04 |
|
Arf posted:
I see these things wrong right off the bat: 1. window.onload, like everything else in JavaScript, is case-sensitive. 2. window.onload needs to refer to the function itself: window.onload = Scroll; Instead, you're calling it and assigning its return value to window.onload. 3. Don't use numbers alone when setting a CSS property that takes a dimension: obj.style.top = pos + "px"; 4. Not strictly wrong, but passing a string as the first argument to window.setTimeout or window.setInterval is bad form, and almost never necessary. Again, you can just pass a reference to the function (don't call the function) instead: window.setTimeout(Scroll, 50); 5. You are not terminating all of your statements with semicolons. This will cause you problems in the future.
|
# ¿ Mar 3, 2009 22:18 |
|
Arf posted:Thanks for your help, turns out it was the pixel thing. Also taken on board your comments about form. Don't worry, this is not going anywhere near anything important. No problem. But it was not just the pixel thing. window.onLoad should *not* have been working. The last line of your code may have happened to work, but that is only because certain things were in a certain order.
|
# ¿ Mar 5, 2009 20:50 |
|
Blackout posted:Hey guys, quick question. I'm trying to write a very simple piece of javascript that does two things. First, it will either show or hide an HTML div with the first id I specify. Second, it will change the text of the div with the second id specified. It should toggle these things, so if the div is shown, it will be hidden and vice versa. Same thing with the text (switches between 'Show...' and 'Hide'). Your JavaScript appears to be up to snuff. I'd have to see some generated HTML, incase there's any funky stuff going on.
|
# ¿ Apr 22, 2009 02:15 |
|
Tivac posted:Arrays can only have numeric indexes, hence why you can't use ['menus']['buckets']. That explanation contradicts you. Crockford posted:Arrays in JavaScript are also hashtable objects. Meaning: because arrays are objects, they can have string-indexed properties. Restating Crockford, the special thing about Array objects is their magical length property. And because of the equivalence of the bracket and dot notations, the length property can be accessed via a["length"], by the way. It is not common to use other string-indexed properties on an array, but it is common to extend Array.prototype with methods, which are nothing more than string-indexed object (or prototype) properties whose values are functions. There Will Be Penalty fucked around with this message at 02:31 on Apr 22, 2009 |
# ¿ Apr 22, 2009 02:27 |
|
One other thing I noticed about JavaScript. The equivalence of the dot and bracket notations for accessing object properties extends to method calls. This includes the aspect that the value of this during the method call is set to the referenced object. Meaning: o.method(args) and o["method"](args) are exactly equivalent. This means you can write code such as the following: code:
EDIT: I know that in most instances you can use $("#div0").toggle(). This is an example. But sometimes you may wish to maintain the state separately. There Will Be Penalty fucked around with this message at 02:44 on Apr 22, 2009 |
# ¿ Apr 22, 2009 02:41 |
|
NotShadowStar posted:Good try, but they mostly just copy/pasted the Mozilla ones which are . Var declarations all over scopes, bit shift operations, The bit-shift operators are most likely being used as a form of type coercion, specifically into a numeric type. I would have just used "foo + 0" myself, but there might be something going on of which I know nothing. Comments would have been nice. They probably copied the MDC code for the reason below (emphasis mine) and simply didn't want to mess with code that worked: Mozilla posted:https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/Filter Above specifically refers to Array.prototype.filter, but the docs for other Array methods on MDC have similar statements.
|
# ¿ Dec 11, 2010 16:03 |
|
NotShadowStar posted:Lua and Ruby the semi-colon is defined as optional. ECMAScript the semicolon is not-optional, but the interpreter tries to fix this for you, and is usually wrong. ECMA-262 posted:7.9 Automatic Semicolon Insertion
|
# ¿ Jan 15, 2011 20:26 |
|
It will not be invoked after an infix operator at EOL. It will also not be invoked if your innermost matching brackets are parenthesis, square brackets, or curly brackets used for object literal notation. I use these as rules of thumb about where it's safe to insert a newline (because gently caress a bunch of lines that are more than 80 columns long). So there's no reason to worry about any of the following statements: code:
code:
There Will Be Penalty fucked around with this message at 06:43 on Jan 16, 2011 |
# ¿ Jan 16, 2011 06:04 |
|
It's innerHTML, not innerHtml. Just about everything is case-sensitive here. Also, this statement code:
EDIT: but when you start thinking about onload handlers and poo poo, I'd say gently caress it and use jQuery.
|
# ¿ Apr 15, 2011 16:49 |
|
Strong Sauce posted:Does returning undefined cause an onsubmit to fail (e.g. not submit)? No. You have to return false. EDIT: returning undefined is the same as not returning a value at all. (All JavaScript functions return a value, really. If you don't specify one, they return undefined.)
|
# ¿ Aug 21, 2016 06:33 |
|
ddiddles posted:So I'm trying to get a better understanding of the this keyword, and i ran into something that confuses me. It's probably because I dont understand JS objects fully, but this code: if you call a function as a method on an object, the `this` value is the object it's invoked on. if you call a function as a function (without an object), the `this` value is either the global object (in non-strict mode) or `undefined` (in strict mode). The value of `this` in the objectMethod call does not apply to inner nested functions like objectMethodFunction.
|
# ¿ Sep 23, 2016 05:24 |
|
Sab669 posted:(Posting from my phone at work, sorry for poor formatting.) Use table_element.querySelector("> tbody > tr > td:nth-child(even)") (I think that would be the correct selector, I know it would work with jQuery.)
|
# ¿ Feb 8, 2017 02:06 |
|
Thermopyle posted:Ehh, "_" has a specific meaning in most languages either by convention or by syntax..."the language requires me to put a variable here but we do not have a use for it." Munkeymon posted:I usually use whocares, dontcare or whatever but that last one isn't super clear, I guess JSLint recommends that you use the identifier ignore. This communicates the idea way better. (I use JSHint these days, which doesn't have that convention.)
|
# ¿ Sep 8, 2017 20:23 |
|
lol if you don't always run your jQuery code in some form of var $ = jQuery;
|
# ¿ Sep 12, 2017 05:10 |
|
|
# ¿ May 4, 2024 16:08 |
|
return false; is an almost-equivalent of event.preventDefault();. event.stopPropagation(); is a different beast.
|
# ¿ Nov 9, 2017 21:40 |