|
Munkeymon posted:Is there a more reliable way of finding the viewable pixel real estate than Prototype's viewport methods? I'm trying to make images shrink to fit the viewport but after a resize, the methods report the document dimensions instead of the dimensions of the window. Since HTML flows down like it's going out of style, I end up with wacky numbers for viewport height (ie bigger than my monitor) and pictures that flow off the screen given otherwise working resize code. This behavior doesn't seem to be entirely consistent since it was working fine at the end of last week in my tests and this morning the same tests are failing. jQuery(window).height(); jQuery(window).wdth();
|
# ¿ Apr 12, 2010 16:26 |
|
|
# ¿ May 17, 2024 15:55 |
|
hasegawa posted:Alright, I'm trying to do a simple form validation for a drop box. I want it to give a "Hey choose something stupid" if the value is still "Select One" when the user clicks submit. With the current code, it allows the user to go to the next page regardless of what they choose in the dropdown box. I've tried several different javascript validators, but none of them seem to work with this. How would the browser know what document.term is? Make sure you are putting in LOTS of debug when learning / trying something new. If you added stuff to your code like so: code:
EDIT with solution: code:
Lumpy fucked around with this message at 22:52 on Apr 25, 2010 |
# ¿ Apr 25, 2010 22:41 |
|
hasegawa posted:Ooh, I see! I wasn't sure how specific I had to be...if merely stating name=term would work or if I needed more precise. Thanks a million! No problems. There was a push by MS back when IE6 was new to have any named element be acessable that way ( or something similar like document.all.someName i forget exact syntax ) but the standard is that you have to use document methods to get a reference to elements.
|
# ¿ Apr 26, 2010 01:05 |
|
roweski posted:Hey guys, completely new to Javascript. Using Flux for mac to create a tv based soundboard for shits and giggles. I've laid it all out, but have no idea how to even go about writing javascript, like, at all.. http://javascript.crockford.com/ Buy his book, and read this thread and look for all the other times people have asked this question and follow the suggestions there. Good luck, and have fun learning javascript. It's a neat little language.
|
# ¿ May 3, 2010 19:42 |
|
Necc0 posted:start at the beginning of the program and move an alert statement line by line to make sure everything is functioning how it should be. Even better, use Webkit's built in javascript debugger ( or whatever the best add-on one for Firefox is these days.. still Firebug? ) and save yourself having to put alerts all over the place! Also, the first "error" in that script is the formatting... Lumpy fucked around with this message at 05:17 on May 6, 2010 |
# ¿ May 6, 2010 05:12 |
|
LeeJam posted:Yeah, I know it's awful. I'm only working with what was given to me. Fun thing is, goofy braces can actually cause Bad Stuff in javascript. Take this example shamelessly stolen from Crockford's "java script: The Good Parts" talk... code:
|
# ¿ May 6, 2010 14:30 |
|
MononcQc posted:I'm writing the JS for a chat app I'm working on in my free time, and I need to have Ids that change according to user submitted data. The "right" answer will depend on what you allow usernames to be. If usernames are email addresses, then you can do strict checking on that for instance. If it's arbitrary, you have a lot more work. Here's a good little guide I have bookmarked: http://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet
|
# ¿ May 8, 2010 15:36 |
|
Vanadium posted:document.getElementById("a").onchange = function() { return an_object.onchange(); }; There is also call: https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Function/call code:
|
# ¿ May 21, 2010 15:04 |
|
KARMA! posted:That's even cooler! Hmm, letss see if crockford can give me some great examples of this.. I'm no Crockford, but: code:
|
# ¿ May 21, 2010 15:54 |
|
peepsalot posted:Haven't looked at igoogle gadgets at all, so I don't know exactly how it works, but there's two main ways I could see being able to strip out the relevant data. I'd go with #2 as well, and here's the code to grab the data: code:
|
# ¿ May 27, 2010 03:36 |
|
JingleBells posted:I'm wondering if there are any recommended resources, books, tutorials and the like related to messing around with the canvas element in javascript? Also anything related to JQuery, I'd like to delve more into JQuery and look at some of the more advanced things you can do with the canvas element. Where I'm working at the moment "cutting edge technology" means working on IE6 (exclusively, we aim to upgrade to IE7 at some point) so I feel I'm getting a little rusty on proper cutting edge stuff https://developer.mozilla.org/en/Canvas_tutorial http://docs.jquery.com
|
# ¿ Jun 2, 2010 16:49 |
|
This is driving me batty. I have an element that is reporting the wrong offsetTop. Using either document.getElementById('myel').offsetTop and jQuery's jQuery('#myel').offest().top both give me 90 as the value... but I know for a fact that the element is at 97, since it's right up against something that's 97px tall that has no margin. In addition, Inspecting the element properties shows me offsetTop is, in fact 97. Lumpy fucked around with this message at 03:37 on Jul 22, 2010 |
# ¿ Jul 22, 2010 02:25 |
|
epswing posted:Can you duplicate this with a minimal example and post it? I can duplicate it, but only on one machine... it's the damndest thing. On my Mac Mini, in Safari and Chrome, I see that ( even after a reboot, cache cleared, etc. ) My iMac and MBP, in both Safari and Chrome, as well as my XP machine with Chrome, FF and IE all report it correctly as 97. I'm going to chalk it up to internet gremlins for now.
|
# ¿ Jul 22, 2010 18:47 |
|
sim posted:I've got a similar, but more complicated question that involves offset. I'm trying to implement this: http://static.jqueryfordesigners.com/demo/fixedfloat.html into my design, but I'd like it to stay contained within a parent div so that it doesn't overlap the footer. I actually managed to do that by calculating the difference between the height of the fixed piece and the height of its container, then checking if position() + scrollTop() was greater than the difference. It would probably be easier to pass it the #footer and use that position().top + #side.outerHeight(true) as a limit. I wrote a plugin that does that "pop out to fixed" a while back, and doing what you are trying to do, plus making sure if the thing you are floating is taller than the viewport it scrolls are on my TODO list. You have motivated me to finish!!
|
# ¿ Jul 26, 2010 03:59 |
|
Finite posted:I'm playing around with jQuery. Before I get into your question proper, you should try not to perform the same selector over and over in your code. Your function should only call $(e) and $(valueBox) once. Speeds tings up a great deal. Also, siblings() already returns a jQuery wrapped object, so you don't need to re-wrap it. As for the actual question: code:
|
# ¿ Aug 4, 2010 16:06 |
|
Rainbow Pony Deluxe posted:Holy poo poo, dude, thank for the advice. jQuery makes Javascript into something resembling a sane programming language. It only took me a couple of minutes to do what I spent hours failing to do in Javascript. Cheers. Javascript is a very sane programming language. code:
|
# ¿ Aug 10, 2010 16:36 |
|
OddObserver posted:That actually works in general, due to Array.prototype.toString So we should always assume we can use an array like a string?
|
# ¿ Aug 10, 2010 17:36 |
|
OddObserver posted:I can't be anywhere that definitive; never thought it out. Except, well, in most contexts where it matters it will indeed auto-coerce into a string value (not to be confused with a string object, of course), e.g.: A = ["A", "B"]; A + "C"; produces "A,BC". And, well, most DOM methods will likely use the ToString operator as well, but those things always have wacko special cases. That was kind of my point. Telling beginners / people who are new to the language that assigning an Array literal where you want a string version of it as "generally OK thing" to do may not be in their best interests.
|
# ¿ Aug 10, 2010 18:45 |
|
NotHet posted:AJAX question! If you are just going to be spinning your wheels until you get your data, you might as well use a synchronous query (I'm using jQuery here because it's easy): code:
|
# ¿ Aug 11, 2010 18:20 |
|
epswing posted:But that will lock up the UI for as long as it takes to fetch the file, which could be half a second, but could also be two or three. Yeah, so you show a "Loading data!" thing... I guess was assuming that locking the UI wasn't an issue because nothing could / should happen until data was loaded. Apparently, I assumed wrong!
|
# ¿ Aug 11, 2010 18:51 |
|
Gentle Marmot posted:
1. Are you serving up the page via a web server, or file:/// url? 2. Why aren't you using jQuery? It makes life so much easier.
|
# ¿ Aug 12, 2010 01:23 |
|
Gentle Marmot posted:Sweet it works... in firefox. IE and google chrome still send the same errors but some searching around seems like chrome broke being able to look at local XMLs like this and I dont care about IE. As Supervillin said, "stuff" is different when not served via http. Chrome actually decided to follow the correct way of doing things with file:/// URLs ( no cookies, etc. ) that "broke" many a thing that had been done using the up until that point "incorrect but everyone did it" way.
|
# ¿ Aug 12, 2010 05:04 |
|
skipdogg posted:I'm creating a .pac file for our computers here at work, and we're rolling out a new proxy appliance that has an issue with a certain tool our agents use and I'm getting stuck trying to work around this. Your code *should* work, since there is a return in every IF. At least I think there is, but your crazy formatting makes it hard to tell. The following behaves as expected: 'a' is matched, and the function returns, so the 'b' if statement doesn't run. code:
Lumpy fucked around with this message at 23:59 on Aug 12, 2010 |
# ¿ Aug 12, 2010 23:54 |
|
emoltra posted:Is there a way that I can replace one element with another? I'm writing a greasemonkey script and am trying to replace td elements with divs. I also need to preserve the class / ID attributes. Uses jQuery, but does what you want, and gets all attributes: code:
|
# ¿ Aug 24, 2010 19:14 |
|
Mackerel, the Thief posted:Brevity version: You have a couple variable names to cut down one letter mister. He might be able to understand those parts.
|
# ¿ Aug 24, 2010 19:53 |
|
Mackerel, the Thief posted:I really want to punch someone whenever I see something like this: Can you come to where I work and start punching people? You've just written every piece of javascript, C, Java, and [ insert language here ] my "boss" writes. EDIT: well, not quite, your code might work.... Lumpy fucked around with this message at 20:04 on Aug 24, 2010 |
# ¿ Aug 24, 2010 20:01 |
|
Tivac posted:You probably want bases on those calls to parseInt or else if the input is something like "08" you aren't going to get the answer you want. Yup. I had to fix a MAJOR BUG in a JS app last week... they had been trying to figure out what was causing the problem for three days. A user was passing '09' as a value to a function that used parseInt, and didn't do any bounds checking and passed of a value that never should have been more than 10 to something else that imploded (that also didn't do any input checking). I love working with people who literally say "well, javascript isn't a real language, so I'm not going to bother learning it; I just need to hack this out and I'll never have to use JS again." Despite having said that for the first time two years ago and having to work with JS more than any other language.
|
# ¿ Sep 2, 2010 00:23 |
|
HFX posted:I could point to quite a few languages who do all the nice stuff Javascript does and better. Great. Did anyone claim there weren't any? For some topic related content, if you sometimes get stuck doing IE only apps like me, I just found out about this pretty awesome performance monitoring tool: http://ajax.dynatrace.com/pages/
|
# ¿ Sep 4, 2010 15:48 |
|
Gentle Marmot posted:I want to be able to write to a json or xml file from a website using javascript. How would I go about doing something like this? I can open them and read just fine out of them using XMLHttpRequest, but is there a way to write? You will have to send the modified json to the server for writing. This can be done with Ajax, but there will have to be some server side scripting for the actual file ( or database) write.
|
# ¿ Sep 22, 2010 03:18 |
|
Gentle Marmot posted:What if I stored to json file locally would that simplify things? Could I just read and write to it from within the javascript? No, Javascript does not have any sort of file system access* due to it running inside the browser sandbox. * you can use HTML5's localStorage to store data, but this is not filesystem access.
|
# ¿ Sep 22, 2010 04:07 |
|
Golbez posted:I can understand wanting to force a type with undefined, integers, floats, booleans, etc... but nothing coerced into a string will ever deliver the correct string. If you try to compare arg1 == "something", if arg1 is an int, there's no way it will ever == "something". It can only ever == "something" if it started out as a string in the first place. So in this case, it seems to me that using === for a non-blank string isn't necessary? How does it hurt to use === instead of == ? And since === is actually faster than == , I guess the better question is why wouldn't you use ===?
|
# ¿ Sep 22, 2010 18:58 |
|
Golbez posted:My question was more along the lines of, why would geeves' coworker even need to do a 'typeof' in this case? The only possible type that can ever == "something" is a string. It's not like == "1", where a string or int could work. Ah, sorry, I misunderstood your point. Yeah, the typeof is pointless in that case. but
|
# ¿ Sep 22, 2010 19:30 |
|
Gentle Marmot posted:Sorry this is just frustrating. Use jQuery. code:
Lumpy fucked around with this message at 19:26 on Sep 29, 2010 |
# ¿ Sep 29, 2010 19:23 |
|
chippy posted:I have a page that is working perfectly in Chrome and Firefox, but IE7 a couple of lines are causing errors. Unfortunately the only error message give is the extremely unhelpful "Object expected" and I don't trust the line numbers it's giving me (one of them seems to be referring to a <TR> tag in a table and not actually a script at all). You can try FireBug Lite or IE Developer Toolbar If you post a link to your code, I'm guessing somebody will be able to quickly see what the problem is. EDIT: If you can, test in IE8 and see if the problem happens there: IE8 actually has a not terrible built in console / debugger. Lumpy fucked around with this message at 13:33 on Oct 1, 2010 |
# ¿ Oct 1, 2010 13:30 |
|
chippy posted:OK, if anyone's interested in helping, pastebin of the entire page is here: http://pastebin.com/YcCypnPG Couple quick things to try: 1. You define the set_assign_to() fuction AFTER the body tag... IE might not like that (although it shouldn't be a problem... but this is IE) 2. On line 285, you call this: code:
There is a lot of "less than best practices" code in there. code:
code:
Lumpy fucked around with this message at 16:30 on Oct 1, 2010 |
# ¿ Oct 1, 2010 16:26 |
|
chippy posted:Well gently caress a duck, I just had to move the "-->" to the end of the script block instead of half way through it. Retard Do yourself a favor and remove those comment things completely. Unless you are supporting Mosaic 0.96, you don't need them.
|
# ¿ Oct 4, 2010 14:53 |
|
ATLbeer posted:So, I'm trying to learn JavaScript objects and making a reusable RSS FeedObject (don't worry about x-browser compatibility) Don't bother with new or this at all..... code:
Lumpy fucked around with this message at 14:01 on Oct 8, 2010 |
# ¿ Oct 7, 2010 22:15 |
|
dark_panda posted:[Good stuff about 'this' and constructors] And that's why I don't bother with prototypical constructors and new. That said, that is an excellent little write-up panda, you should post it somewhere. dark_panda posted:I highly recommend his video series on JavaScript on YUI Theatre, as they're well worth watching. They're the sort of videos where, yeah, they're focused on JavaScript, but he packs so much history of our industry into the videos that they could have well been about BASIC and been just as interesting. These are must-watches for anyone doing JS, and like you said, a really cool history even if you don't.
|
# ¿ Oct 8, 2010 14:00 |
|
wins32767 posted:I need a visualization/graphing JS library. Any suggestions? Flot: http://code.google.com/p/flot/
|
# ¿ Oct 19, 2010 19:00 |
|
|
# ¿ May 17, 2024 15:55 |
|
DholmbladRU posted:i am not sure if this is a Js question or html. It's a javascript question. You want to attach a keyup event to the input, and every time they enter something, pass the value through a regex that removes all non-digits, then adds commas in the right places, and sets the form input to that new string. Tivac posted:
code:
Lumpy fucked around with this message at 01:11 on Oct 20, 2010 |
# ¿ Oct 20, 2010 01:09 |