|
Yes. JavaScript code:
Wheany fucked around with this message at 08:55 on Nov 6, 2012 |
# ? Nov 5, 2012 19:49 |
|
|
# ? Jun 1, 2024 06:02 |
|
Does setting a submit button to disabled cause its form to not submit? Here's what I have (sorry I don't have the code with me right now to show): A form that will be validated via JavaScript first and then by PHP. The form has an onsubmit event function to validate the fields. Inside the JS function I've disabled the submit button and re-enabled it only when a field is found invalid so that the user is able to click it again. If all fields are valid, I return from the function and the method="post" kicks in and the form is validated server-side via PHP. However, that last step never happens. When JS finds the fields valid and returns from the function, the form doesn't submit. That is, until I place "submitBtn.disabled = 'false'" right before returning from the function. Is this how it should be? The reason I ask is because I just finished a JS book with an exercise that did this very thing (validate form in JS, disable button, re-enable if invalid, submit form once validated), but in the example the form was submitted WITHOUT having to first set submitBtn.disabled to false. The only difference is that the book's example did not do any server-side validation, it simply submitted the form. Just wanting to make sure I understand what's going on.
|
# ? Nov 8, 2012 16:38 |
|
caiman posted:Does setting a submit button to disabled cause its form to not submit? Here's what I have (sorry I don't have the code with me right now to show): A form that will be validated via JavaScript first and then by PHP. The form has an onsubmit event function to validate the fields. Inside the JS function I've disabled the submit button and re-enabled it only when a field is found invalid so that the user is able to click it again. If all fields are valid, I return from the function and the method="post" kicks in and the form is validated server-side via PHP. However, that last step never happens. When JS finds the fields valid and returns from the function, the form doesn't submit. That is, until I place "submitBtn.disabled = 'false'" right before returning from the function. Is this how it should be? Can you post your JS validation code?
|
# ? Nov 9, 2012 03:31 |
|
DankTamagachi posted:Can you post your JS validation code? Sure. Here's how it looks when it does not work: code:
|
# ? Nov 9, 2012 16:21 |
|
An AJAX question. What is the proper technique for validating a form via JS when one of the fields requires server-side validation? For instance, take a look at the code I posted in the post above this. Now imagine that the Username field must also be checked against the database to see if the name already exists. I want the "Sorry username already exists" alert to feel seamlessly a part of the other client-side validations. Here's my general outline of this process. Please let me know if this is way off. -Form's onsubmit event triggers a function called submitForm(). -submitForm() calls a function called ajaxUtility() and passes paremeters such as the url of the php file and the name of the function to process the response. -ajaxUtility() does all the ajax stuff - creates the XHR object, checks its ready state and status, and sends the response from the server file to a function called processResponse() (the response being a simple text string indicating if the user name exists in the db or not). -processResponse() looks at the responseText and, if it's "exists", shows the "screen name exists" alert. If it's "not exists", the validateForm() function is called and the rest of the form is validated. -When the rest of the validation is finished, the form submits and the server-side validation kicks in. Am I on the right track here?
|
# ? Nov 14, 2012 17:51 |
|
caiman posted:An AJAX question. I'm guessing you want this to be a smooth experience; you click the submit button, a little spinner comes up, and if there are problems with the submission then it displays them without having to reload the form. My general feeling is, client-side validation should be done on change rather than submit. So as the field blurs, that is when it should check with the server to see if the username is taken, not on submit. Especially when that's the only field that you need to communicate with the server to validate. But that's just me. Note that you still need to account for things that get past the Javascript (username acceptable when preliminary validation passed but not by the time the second one ran, etc). That could still be integrated into your smooth form.
|
# ? Nov 14, 2012 18:06 |
|
Golbez posted:I'm guessing you want this to be a smooth experience; you click the submit button, a little spinner comes up, and if there are problems with the submission then it displays them without having to reload the form. Yeah, I'll probably eventually opt to do the onBlur thing rather than onSubmit. But for now I'm just needing to know if my general logic is correct.
|
# ? Nov 14, 2012 18:09 |
|
I've been trying my hand at web development recently, never done it before and my only programming experience has been with Python. I'm trying to create an order form where the total price is dynamically updated (using Javascript I guess?) when the quantity is incremented for a given item. I'm using Flask to supply a template with the name/prices of the items from a database and the relevant part of the order form looks like this: code:
|
# ? Nov 14, 2012 19:16 |
|
caiman posted:Yeah, I'll probably eventually opt to do the onBlur thing rather than onSubmit. But for now I'm just needing to know if my general logic is correct. Looks fine to me.
|
# ? Nov 14, 2012 20:37 |
|
Begall posted:I've been trying my hand at web development recently, never done it before and my only programming experience has been with Python. I'm trying to create an order form where the total price is dynamically updated (using Javascript I guess?) when the quantity is incremented for a given item. These are server-side templates, where is the dynamic updating happening?
|
# ? Nov 14, 2012 20:37 |
|
Begall posted:
Guessing from the code, since I have never programmed in whatever that is, and because I don't know what kind of values entry.name can contain, instead of <input id="DQuantity-{{ entry.name }}">, I'd use <input name="DQuantity-{{ entry.name }}" type="number" id="DQuantity-{{ loop.index }}" placeholder="0" class="quantity">. For <td name="DPrice-{{ loop.index }}" id="DPrice-{{ loop.index }}">, I would also add data-price attribute, so <td name="DPrice-{{ loop.index }}" id="DPrice-{{ loop.index }}" data-price="{{ entry.price }}"> (again, guessing the syntax). Then I would do this: JavaScript code:
|
# ? Nov 14, 2012 22:07 |
|
Sorry for not being quite clear on the code, but that was of great help, thanks! Here's what I've done, I think this is what you intended? JavaScript code:
|
# ? Nov 15, 2012 00:40 |
|
while we're here can we talk about the problem of binding the same keydown or keypress event to two different behaviors here on the SA Forums? (the hotkey for submit will also add strikethrough to whatever word the cursor is hovered over, or something like that. it is annoying!)
|
# ? Nov 15, 2012 02:31 |
|
Begall posted:Sorry for not being quite clear on the code, but that was of great help, thanks! Well, almost. Actually I didn't even think of having to update the total cost of the shopping cart, but the reason I added the change listener to all inputs was to update just the row's price, with this.value * <the same row's price>. And the reason I wanted you to use data- attribute, is because they are special: https://developer.mozilla.org/en-US/docs/DOM/element.dataset No need to getAttribute("data-price"), just use dataset["price"]. Not that it matters a whole lot. And updating the innerHTML is probably not a problem in this case, since you are uppading a number, but if the string you are inserting into an element is not supposed to be HTML, you should use .textContent (non-IE browsers) or .innerText (non-gecko browsers) (if element.textContent === undefined, use innerText) Or, use jQuery and let them worry about those kinds of things.
|
# ? Nov 15, 2012 08:26 |
|
Wheany posted:Well, almost. Actually I didn't even think of having to update the total cost of the shopping cart, but the reason I added the change listener to all inputs was to update just the row's price, with this.value * <the same row's price>. And the reason I wanted you to use data- attribute, is because they are special: Just in case you don't know - the native dataset API isn't implemented in any version of IE, and you have to fall back to getAttribute... yes, even for IE10.
|
# ? Nov 15, 2012 11:05 |
|
Has anyone worked with Meteor.js? I went to my first front-end developers meetup last night and our project is going to be based around Meteor. I've never worked with node before, so it's a lot to catch up on but it look pretty cool. Because it's new, I'm not getting the amount of results I'd usually get on Stack Overflow or sites like that, has anyone found a good resource?
|
# ? Nov 15, 2012 15:00 |
|
That's because it is very new, has its own incompatible standards for everything, and only recently added exciting edge features like 'authentication' which make non-toy projects possible. I'd bet you won't find anything better than the official documentation for at least a year. (I don't want to sound like an utter hater: it's pretty magical, I'm just sad that the team making it seems to want to build their own ecosystem up instead of letting developers leverage existing node/javascript stuff. )
|
# ? Nov 15, 2012 17:16 |
|
Sergeant Rock posted:Just in case you don't know - the native dataset API isn't implemented in any version of IE, and you have to fall back to getAttribute... yes, even for IE10. Well, at least getAttribute works across all browsers Oh well, it's poo poo like this why you should use libraries.
|
# ? Nov 15, 2012 18:45 |
|
Doc Hawkins posted:That's because it is very new, has its own incompatible standards for everything, and only recently added exciting edge features like 'authentication' which make non-toy projects possible. I'd bet you won't find anything better than the official documentation for at least a year. I just started on some Node development and there's pretty scarce resources for broadcasting and pub/sub outside of two or three websites that are geared towards the java end of development in Node. It's amazing stuff, though. ZMQ and Meteor are the best frameworks I've seen out of it so far.
|
# ? Nov 16, 2012 20:21 |
|
I was reading through a bit of the underscore.js source code and I noticed that in a few places he used:code:
code:
|
# ? Nov 17, 2012 23:22 |
|
No. results.push(value); is defined to be the same as results[results.length]=value;
|
# ? Nov 17, 2012 23:31 |
|
Well, one benefit is that it works even when someone messed up Array.prototype.push. (Also if it doesn't exist, which was the case for some prehistoric IE, not sure of which versions, though).
|
# ? Nov 17, 2012 23:46 |
|
But it wouldn't work if somebody hosed up Number.prototype.toString! (seriously, playing this whole game is dumb)
|
# ? Nov 17, 2012 23:55 |
|
I have some JavaScript that uses setInterval to increment the alpha value of the background-color of an element:code:
Spatulater bro! fucked around with this message at 00:25 on Nov 18, 2012 |
# ? Nov 18, 2012 00:18 |
|
caiman posted:I have some JavaScript that uses setInterval to increment the alpha value of the background-color of an element: This doesn't directly answer your question, but this code seems to work: http://jsbin.com/ojecop/1/edit
|
# ? Nov 18, 2012 01:11 |
|
Bodhi Tea posted:This doesn't directly answer your question, but this code seems to work: Yeah, that's pretty close to how I got it to work. But the problem I ran into was when I wanted to also do a fade OUT effect on mouseout. Since the actual rgba value was giving all sorts of extra decimal places, it was difficult to get it to work. I've figured it out, but I'd really like to understand why the code doesn't put the clean rounded value (i.e. "0.1") into the backgroundColor value.
|
# ? Nov 18, 2012 01:17 |
|
caiman posted:Yeah, that's pretty close to how I got it to work. But the problem I ran into was when I wanted to also do a fade OUT effect on mouseout. Since the actual rgba value was giving all sorts of extra decimal places, it was difficult to get it to work. I've figured it out, but I'd really like to understand why the code doesn't put the clean rounded value (i.e. "0.1") into the backgroundColor value. I believe it is due to the way floating point numbers are handled: http://stackoverflow.com/questions/1458633/elegant-workaround-for-javascript-floating-point-number-problem
|
# ? Nov 18, 2012 01:19 |
|
^^^Didn't see your reply. If that's the case, shouldn't val also be set to to "0.0980392"? Or maybe I'm not understanding something. For clarification, these screenshots are taken at the same point in the same iteration: And: Spatulater bro! fucked around with this message at 01:28 on Nov 18, 2012 |
# ? Nov 18, 2012 01:25 |
|
It could be that ecmascript standard defines variables with more bits than the css' standard does for the rgba function.
|
# ? Nov 18, 2012 04:30 |
|
The Number type in Javascript is your standard IEEE 754 double. For CSS, I don't think there's a required precision (or even a minimum) specified anywhere. As an aside, if you don't care about old versions of IE you can (and should!) use CSS transforms instead of doing it manually in javascript.
|
# ? Nov 18, 2012 04:41 |
|
I have no idea if anyone will find this useful, but here are some shortcomings I've run into with Kendo grid over the past few weeks. - Cannot dynamically change the grid in and out of editable mode. Reloading just the div the grid is contained in doesn't seem to work either, I'm having to do a full page reload to get around this. - Cannot disable animation of modal pop-up used for editing grid contents - Cannot have icon only "edit/new/delete" buttons in grid. Well, you can put no text, but the padding is messed up and the buttons look retarded. - Row and/or cell selections are lost when columns are sorted. - JSON datasource must be perfectly flat, no nesting is supported - Delete confirmation pop-up is not styled by default These of course can all be gotten around (well, kinda). It's just annoying.
|
# ? Nov 18, 2012 19:39 |
|
Bodhi Tea posted:I was reading through a bit of the underscore.js source code and I noticed that in a few places he used: They do that to protect data, it's a cross-site scripting thing. Basically someone could override the results.push() method to their own nefarious ends, but you can't exploit results[results.length] putin is a cunt fucked around with this message at 02:06 on Nov 20, 2012 |
# ? Nov 20, 2012 01:05 |
|
Gnack posted:They do that to protect data, it's a cross-site scripting thing. Basically someone could override the results.push() method to their own nefarious ends, but you can't exploit results[results.length] What attack are you actually protecting against here? If an attacker is running javascript on your page, you've already lost the XSS game and not letting them override Array.push isn't going to save you. If you're embedding user data in your javascript and letting someone else execute it, you're also playing with fire and you're better off doing that in a more secure way instead of trying to protect yourself with some cute tricks. And if neither of those are true, you shouldn't really care if someone messes with it because it doesn't expose any new security vulnerabilities.
|
# ? Nov 20, 2012 08:18 |
|
https://github.com/documentcloud/underscore/commit/19acc63374299828e25d5e55d5004f562fc6b20f According to the commit, it was changed for "speed". Bit dubious about this since from what I've read from speed tests push has been rated faster than array[len] = val.
|
# ? Nov 20, 2012 08:52 |
|
http://jsperf.com/push-vs-index2
|
# ? Nov 20, 2012 09:06 |
|
Jabor posted:What attack are you actually protecting against here? I'm building an offline and sync web application so this sort of interests me, I've been thinking a bit about how security works what with alot of your code readily accessible. It's just an offline prototype at the moment, but I'm planning on syncing through JSON and a standard authenticated login session. Is there anything particularly naive about this? Are there any recommended resources available for security best practices in javascript applications?
|
# ? Nov 20, 2012 10:49 |
|
I'm trying to do a drag'n'drop functionality on a website, but JavaScript is messing with me.code:
|
# ? Nov 20, 2012 13:12 |
|
... which shows that push is faster on everything except one version of Chrome?
|
# ? Nov 20, 2012 16:49 |
|
Maluco Marinero posted:I'm building an offline and sync web application so this sort of interests me, I've been thinking a bit about how security works what with alot of your code readily accessible. It's just an offline prototype at the moment, but I'm planning on syncing through JSON and a standard authenticated login session. Is there anything particularly naive about this? Are there any recommended resources available for security best practices in javascript applications? Can you elaborate a little bit more on the web app you're working on? I've been thinking about developing a similar system and I'm curious if you could discuss issues you've run into with with offline data.
|
# ? Nov 20, 2012 17:37 |
|
|
# ? Jun 1, 2024 06:02 |
|
Suspicious Dish posted:... which shows that push is faster on everything except one version of Chrome? I didn't make a comment either way. IE10 smokes everything :P
|
# ? Nov 20, 2012 19:06 |