|
Wheany posted:Is the data returned from page B a complete html file, or just a fragment? $("#result").html(data); sets the innerHTML of the element whose id is "result" to the html that is returned, so that might not work if it's a complete page and not just a fragment. Yeah it was a complete page, rather than a fragment, so I figured that wouldn't work. And I did have an id element like that, but I guess it wouldn't have worked anyway. Sorry to have wasted your time, but I have fixed it by not using the jQuery at all and just using hidden inputs which seems to work ok, I need a break
|
# ? Mar 17, 2014 19:20 |
|
|
# ? May 15, 2024 13:14 |
|
fakemirage posted:I can spot two issues in your validation function that will stop it from running. Cool, thanks. I'll make these changes and see if it runs. *E* Nope, still not working for me. Do I need to give the function a value to return? Or possibly pass? Agh, I'm so confused. IronSaber fucked around with this message at 20:51 on Mar 17, 2014 |
# ? Mar 17, 2014 20:05 |
|
IronSaber posted:Cool, thanks. I'll make these changes and see if it runs. You call document.getElementById in your head-tag (line 62-69), before the browser has gotten to the body-tag (i.e. you're trying to get elements that doesn't exist yet). Since you don't actually use them anywhere it would be safe just to remove them, and get your script running (with the assumption that everything else is working, like the GetCookie function which I can't find in your pastebin, but you call in your script) or just run it later when the body and DOMTree has finished loading (like you've done with updateDisplay). Just note that the value you get is the value of the field as the line is executed; so if you retrieve the value of the element firstName as the document has just finished loading, the variable you stored the first name in will always be empty (since that's the value it gets by default). fakemirage fucked around with this message at 21:32 on Mar 17, 2014 |
# ? Mar 17, 2014 21:30 |
|
fakemirage posted:The phoneCheck function itself should work if you corrected the lines highlighted. As for the rest of the script, there's one thing I've noticed specifically: I see. But the function runs only after onBlur is invoked from the phone number field. I would assume that after a number is entered and someone moves on to another field to enter, the onBlur would run the phoneCheck() function and grab the data currently in the field. The getCookie function is from another page in this project; it's supposed to take the order of a pizza you enter and carry it over to this page. I will have to write up another function to take the customer data from this page and store it in cookies to take to the final Order Confirmation page along with the pizza cookies. Heh... pizza cookies.
|
# ? Mar 17, 2014 21:53 |
|
IronSaber posted:I see. But the function runs only after onBlur is invoked from the phone number field. I would assume that after a number is entered and someone moves on to another field to enter, the onBlur would run the phoneCheck() function and grab the data currently in the field. I was commenting on lines 62 through 69, that doesn't run in the phoneCheck function.
|
# ? Mar 17, 2014 21:58 |
|
fakemirage posted:That's absolutely correct, you'll get what is currently entered in the phone number field when you call phoneCheck. Oh, so you mean that the var phoneNumber = document.getElementById("phone"); should be inside the function itself? *E* Holy poo poo! It works! Fakemirage, you are my hero. Thank you for helping me out! IronSaber fucked around with this message at 22:27 on Mar 17, 2014 |
# ? Mar 17, 2014 22:08 |
|
I've been asked to automate a simple "log in to dashboard, click button, accept download, repeat from step 2" workflow on a site that's extremely AJAX heavy and complicated, so I figured I'd just slap it together with casperjs/phantomjs and it'd be a fun afternoon getting deeper into those projects than "I read a blog article one time". Indeed it was easy to get my script to the point where it was requesting and actually receiving the report - as a Content-Disposition: attachment to a POST response, which is something phantom just can't cope with very well unless you go get one obscure branch and build that. After a rousing of morning cleaning up broken build scripts and waiting for OpenSSL and Qt to compile, I have a fancy newfangled phantom build that just falls on its face instead of completing the login step. Now I'm recompiling once more with
|
# ? Mar 18, 2014 21:14 |
|
Sounds like something that should be handled server-side. Deal with the form inside your one-page app, then provide a link to another page that serves a file, perhaps? Maybe add a parameter to the file serving page to require a disposable key.
|
# ? Mar 18, 2014 21:52 |
|
I think you misunderstand: I'm scraping content from someone else's server.
|
# ? Mar 18, 2014 22:29 |
|
Munkeymon posted:I think you misunderstand: I'm scraping content from someone else's server. Have you considered just using Greasemonkey (Tampermonkey on Chrome)? It seems like almost exactly what you want.
|
# ? Mar 19, 2014 00:27 |
|
Now I'm having more issues getting this project up and running, and I dunno if anyone will be able to respond in time to help me. So here's the code for all three pages of my project: index.html: http://pastebin.com/w73LGp6Z custInfo.html: http://pastebin.com/eL3Bgba8 summary.html: http://pastebin.com/cbyrZFsY I'm stuck on a couple areas: -Need to get the subtotal function to dynamically display all combinations of cost of crust and toppings -Need to get it all stored as cookies and transferred to the next page and the page after that -Need to get the custInfo page to run the inputCheck upon clicking the submit button (I know this requires the 'onsubmit' function, but I have no idea where to place it) I have several more functions that need to be put in, but I don't want to make anyone else do this project for me.
|
# ? Mar 19, 2014 06:47 |
|
IronSaber posted:I'm stuck on a couple areas: - onsubmit is something you can add to your form element, probably like this: <form name="custInfo" action="summary.html" method="post" onsubmit="return inputCheck();">. Remember to use return if you want inputCheck to be able to stop the submission if the data isn't valid. - Storing the form in cookies is something you'll probably do after validating that the data is correct, so maybe it should be done in the inputCheck method, or a function that you at least run when you submit the form. If you're unsure how to save and read cookies, there are plenty of tips and complete functions to find through google. - For the dynamic subtotal, you should probably use the price array, iterate over it and get the sum. (example).
|
# ? Mar 20, 2014 10:11 |
|
Subjunctive posted:Have you considered just using Greasemonkey (Tampermonkey on Chrome)? It seems like almost exactly what you want. That was a good thought, but, after looking into it, I wasn't able to find any way to change the location or name of the file downloaded*. That's a problem when all of the files are named something like date_range.csv and all get saved to the same place. I did eventually get a build of phantom working that gave me access to the request data and didn't crash all over the place, so it turned out OK in the end. * I admit it's possible that I didn't look hard enough, but I did look
|
# ? Mar 22, 2014 08:48 |
|
Munkeymon posted:That was a good thought, but, after looking into it, I wasn't able to find any way to change the location or name of the file downloaded*. That's a problem when all of the files are named something like date_range.csv and all get saved to the same place. I did eventually get a build of phantom working that gave me access to the request data and didn't crash all over the place, so it turned out OK in the end. If you just want to save it client side there's the html5 download attribute for Chrome/Firefox and msSaveBlob for IE10+; IE9 can only save text/html using execCommand.
|
# ? Mar 22, 2014 11:02 |
|
I'm not sure which of the JS/Web dev threads to put this in, so here goes: I'm looking for a minimal unit testing suite/framework. At the moment I'm still writing stuff that is manageable in a single file, wrapped within a single anonymous function. I'd really like it if I could just write a bunch of unit tests in another single file to test all the functions that don't rely on the DOM. Maybe pass both files (or just the test file) to a node.js cli tool. Then it runs the tests and poops out the test results to the console. Basically, just change what I currently do: code:
code:
e: Welp, probably should have googled better before posting, maybe mocha is what I want? Xik fucked around with this message at 11:11 on Mar 22, 2014 |
# ? Mar 22, 2014 11:07 |
Xik posted:I'm not sure which of the JS/Web dev threads to put this in, so here goes: It might be a bit of overkill for your current needs, but I have been extremely happy with a Karma/Jasmine combo.
|
|
# ? Mar 22, 2014 13:33 |
|
Brave GNU World posted:If you just want to save it client side there's the html5 download attribute for Chrome/Firefox and msSaveBlob for IE10+; IE9 can only save text/html using execCommand. None of which I could use AFAICT because these files are delivered as attachments to POST responses, not links as actual links that I could manipulate in the DOM. I think Opera might have an event user scripts can hook to look at requests, but I couldn't find anything for Chrome. Actually, it was a pain in the rear end finding anything about user scripts for Chrome that wasn't horribly outdated.
|
# ? Mar 22, 2014 17:58 |
|
Munkeymon posted:None of which I could use AFAICT because these files are delivered as attachments to POST responses, not links as actual links that I could manipulate in the DOM. I think Opera might have an event user scripts can hook to look at requests, but I couldn't find anything for Chrome. Actually, it was a pain in the rear end finding anything about user scripts for Chrome that wasn't horribly outdated. Sometimes it's a bit of a pain in the rear end trying to use user javascript files on Chrome compared to Opera (<15). On opera, they explicitly have higher privileges than in-page scripts and you can freely access the global state of the page. On Chrome they're too concerned about "sandboxes" and "security" to let me do that
|
# ? Mar 22, 2014 22:02 |
|
Munkeymon posted:None of which I could use AFAICT because these files are delivered as attachments to POST responses, not links as actual links that I could manipulate in the DOM. I think Opera might have an event user scripts can hook to look at requests, but I couldn't find anything for Chrome. Actually, it was a pain in the rear end finding anything about user scripts for Chrome that wasn't horribly outdated. You don't need actual links, you just create an element in javascript and set the href to the file type/data and download to the file name, add it as an invisible element to the DOM, call click on it and get rid of it.
|
# ? Mar 23, 2014 14:01 |
|
Brave GNU World posted:You don't need actual links, you just create an element in javascript and set the href to the file type/data and download to the file name, add it as an invisible element to the DOM, call click on it and get rid of it. How do you get that to send a POST? I think he'll need XHR for that, which is also an option. The content-disposition stuff is such a mess. :-(
|
# ? Mar 23, 2014 14:26 |
|
Osmosisch posted:It might be a bit of overkill for your current needs, but I have been extremely happy with a Karma/Jasmine combo. I got things setup with mocha (testrunner) and chai (assertions), but had to settle on using the html reporter instead of the cli. Unless I'm missing something obvious, there is no sane way to use my script as a module in node without making GBS threads it up with an export statement. So writing tests and running mocha via the command line is a no go for scripts intended for the browser. I've got a (probably dumb) question. Can I rely on the browser blocking when loading a resource via the script tag? I read about the html5 async attribute for the script tag and now it has me worried. In the following snippet will MYMODULE always be available? Can I always rely on that? Is there a more appropriate pattern for doing this without moving the original call into the script itself? code:
code:
|
# ? Mar 23, 2014 22:26 |
|
Xik posted:I've got a (probably dumb) question. Can I rely on the browser blocking when loading a resource via the script tag? I read about the html5 async attribute for the script tag and now it has me worried. Yes, that's safe unless you make the first script tag async explicitly. Note that script tags may be *fetched* ahead of script execution flow, as a networking optimization, but in the absence of async they must be *executed* in page/DOM-insertion order. Every site in the world that uses out-of-line JS scripts relies on this, so you're safe.
|
# ? Mar 23, 2014 23:38 |
|
Thanks Subjunctive. I'm glad there is at least one thing about the DOM that makes sense.
|
# ? Mar 24, 2014 00:19 |
|
Xik posted:Thanks Subjunctive. I'm glad there is at least one thing about the DOM that makes sense. Not too much, though: we tried to keep people on their toes.
|
# ? Mar 24, 2014 00:22 |
|
Wheany posted:Sometimes it's a bit of a pain in the rear end trying to use user javascript files on Chrome compared to Opera (<15). On opera, they explicitly have higher privileges than in-page scripts and you can freely access the global state of the page. On Chrome they're too concerned about "sandboxes" and "security" to let me do that Yeah, I'm gonna miss that when 12 finally gets too far behind the times to justify using. RIP Opera's good days
|
# ? Mar 24, 2014 19:17 |
|
Subjunctive posted:How do you get that to send a POST? I think he'll need XHR for that, which is also an option. The content-disposition stuff is such a mess. :-( Tried that, actually. I could never even get a repeated request to work, even when I had Fiddler replay it so I knew it was the same.
|
# ? Mar 24, 2014 19:23 |
|
Munkeymon posted:Yeah, I'm gonna miss that when 12 finally gets too far behind the times to justify using. RIP Opera's good days
|
# ? Mar 24, 2014 19:31 |
|
Misogynist posted:Opera's been WebKit-based for awhile now - where are you afraid of it falling behind? Opera 12, not the entirely unrelated blink-based browser.
|
# ? Mar 24, 2014 20:05 |
|
I don't know if this should go in the Clojure thread or here, but for anyone fairly familiar with it, does Clojurescript eliminate any major Javascript warts(that Coffeescript doesn't)? I've played around with it a bit, enough to get the basic syntax down, but as of yet there hasn't been any wow moments.Xik posted:I'm not sure which of the JS/Web dev threads to put this in, so here goes: Both Jasmine and Mocha are probably going to be somewhat too heavyweight for what you want. They're usable, but if you want something simpler I'd suggest one of the various doctests for javascript. They're the next step up from testing by sprinkling asserts into your code.
|
# ? Mar 25, 2014 10:55 |
|
The Insect Court posted:I don't know if this should go in the Clojure thread or here, but for anyone fairly familiar with it, does Clojurescript eliminate any major Javascript warts(that Coffeescript doesn't)? I've played around with it a bit, enough to get the basic syntax down, but as of yet there hasn't been any wow moments. While you're trying out compile to JavaScript stuff, be sure to check out Typescript. It addresses a very different focus than Coffee script, in that rather than syntax it focuses on large scale problems like contract behaviour with static typing, and has a really well thought out approach to JavaScript interoperability so bringing in libraries is not a big drama. Certainly where I'm making my switch, doesn't hurt that the syntax is basically ES6 too.
|
# ? Mar 25, 2014 11:10 |
|
The Insect Court posted:Both Jasmine and Mocha are probably going to be somewhat too heavyweight for what you want. They're usable, but if you want something simpler I'd suggest one of the various doctests for javascript. They're the next step up from testing by sprinkling asserts into your code. I'm not sure if I really like the concept of putting unit test in comments within the main script. I appreciate the suggestion of an alternative solution though. I had another look at trying to find a "proper" way to export a script intended for the browser to a commonjs/node module. As far as I can tell, there really isn't one (please correct me if I'm wrong). So I just settled and did it in a sort of gross way. code:
Now I can run it in both the browser and require it within a mocha unit test file to run from the command line. So now I: code:
|
# ? Mar 26, 2014 11:49 |
|
Strong Sauce posted:Trailing dots don't make any sense at all. It's also very easy to get an error when you decide to delete the last command. Prepending dots helps it naturally align and doesn't cause any problems. Trailing dots do make a bit of sense, but not enough that I'd use them. Basically they're just an explicit attempt to keep Javascript's "hey, this line didn't execute properly, so let's back up one line, throw a semicolon on it, and try it again" behavior from NOT breaking your code. That is, if you're a sane person and using semicolons like Crockford intended, then you WANT the interpreter to poo poo itself when a semicolon is missing, not just toss one on there and merrily proceed with some potentially hosed up logic. By using trailing dots you make your code completely un-interpretable in situations where it otherwise may not be. Xik posted:I just settled and did it in a sort of gross way. This is actually how pretty much every "which loader are you using?" block I've ever seen detects the use of commonJS modules. While yes, it is technically possible that there will be a "module" object in the current scope with an "exports" property that's also an object, the chance of that happening and it NOT being a commonJS loader is so, so small that I wouldn't ever worry about it. In fact, most of them don't even bother checking for "module". There is a "Universal Module Definition" that's kind of been loosely agreed upon by various JavaScript organizations/foundations/eggheads, details of which can be found Here. The "returnExports" pattern is the one I see most often "in the wild," but I do primarily front-end development. Here's the version of the returnExports pattern that assumes dependencies: JavaScript code:
|
# ? Mar 26, 2014 17:24 |
|
isochronous posted:There is a "Universal Module Definition" that's kind of been loosely agreed upon by various JavaScript organizations/foundations/eggheads, details of which can be found Here. Great post, thanks isochronous. I wish I had known about this sooner.
|
# ? Mar 26, 2014 17:49 |
|
No problem, it's amazing what you can find on github.
|
# ? Mar 26, 2014 21:05 |
|
The Insect Court posted:I don't know if this should go in the Clojure thread or here, but for anyone fairly familiar with it, does Clojurescript eliminate any major Javascript warts(that Coffeescript doesn't)? I've played around with it a bit, enough to get the basic syntax down, but as of yet there hasn't been any wow moments. Clojure is a cool and good language, and using immutable data structures in js has some hefty potential performance wins. The above article is one of the reasons I really, really wanted to hurl myself into clojurescript, but my experience was that the integration with the javascript ecosystem was essentially absent.
|
# ? Mar 26, 2014 21:19 |
|
Doc Hawkins posted:my experience was that the integration with the javascript ecosystem was essentially absent.
|
# ? Mar 26, 2014 21:37 |
|
It isn't an inherent problem, the trade-off just went the other way for me. If everything you need is on clojars, there's few downsides.
|
# ? Mar 26, 2014 22:05 |
|
Subjunctive posted:I unreservedly recommend http://effectivejs.com/ -- Dave is a great writer, understands JS as deeply as any human alive, is a great teacher, and has a lot of experience teaching and working with a variety of languages. I worked on JS engines (including with Dave) for many years, and recommend this to everyone. I picked this up a bit ago and it is great. I'm not normally a "Programming Book" kind of dude but this one is definitely worth the $$. Doc Hawkins posted:Clojure is a cool and good language, and using immutable data structures in js has some hefty potential performance wins. React looks pretty cool (was talked about in that article). Anyone here have any thoughts on it / have worked with it?
|
# ? Mar 27, 2014 14:13 |
|
Tres Burritos posted:I picked this up a bit ago and it is great. I'm not normally a "Programming Book" kind of dude but this one is definitely worth the $$. React is awesome. Performance absolutely destroys Angular and its much easier to manage state well. You're a lot closer to how the DOM renders too so you can make even greater performance gains without massively changing the components you're using.
|
# ? Mar 28, 2014 08:29 |
|
|
# ? May 15, 2024 13:14 |
|
Maluco Marinero posted:React is awesome. Performance absolutely destroys Angular and its much easier to manage state well. You're a lot closer to how the DOM renders too so you can make even greater performance gains without massively changing the components you're using. This post made me watch that Peter Hunt video (well, actually the updated version here). I gotta say it seems like I will like this more than Angular. Angular is cool and all, but it looks like I will find React a lot more intuitive.
|
# ? Mar 28, 2014 16:55 |