Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



LLSix posted:

I recently started a new job working on a browser-based application and am still learning the finer points of Javascript. I've got a question about what a JS interpreter following the spec should do with the following code snippet.

code:
node_list_foo = document.getElementsByName("bar");
//node_list_foo is now a node list with a length of lets say 3.
var element_from_item = NodeListFoo.item(4);
//element_from_item is now NULL according to [url]https://dom.spec.whatwg.org/#interface-nodelist[/url]
var element_from_index = NodeListFoo[4];
// my broswers are setting element_from_index to undefined in this case, but what should it be?
https://dom.spec.whatwg.org/#interface-nodelist appears to defer defining the behavior of out of range indices to the definition of supported-property-indices, am I reading that right?

If I'm reading that right, the spec says the behavior of the two access methods should be the same? So both should return undefined;

Curiously, https://developer.mozilla.org/en-US/docs/Web/API/NodeList, documents the observed behavior and not the behavior that I think the spec calls for.

What's the correct interpretation of the spec and is there another approach I should take to finding out how these kinds of things work?

Finally, if my interpretation of the spec is correct; nobody seems to actually follow the spec for using array style syntax; so as a paranoid and perfectionist programmer should I be using nodelist.item(x) as the preferred approach?

.item() isn't a 'property getter' as I would understand the term, but rather just a method on an object. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get is probably what that quote means by 'property getter'. Given that, NodeListFoo[4] is just getting property '4' from the object NodeListFoo and, since the NodeList behaves like an array (sometimes 😒) or vanilla object, I would expect that to evaluate to undefined rather than null. I think .item() returns null because returning undefined would be just pretty fuckin weird since methods don't generally do that sort of thing whereas accessing properties that don't exist generally do.

Adbot
ADBOT LOVES YOU

teen phone cutie
Jun 18, 2012

last year i rewrote something awful from scratch because i hate myself
Does anyone have any suggestions for HTTP request interceptor software for Mac OS?

I'd like to be able to set breakpoints and edit both HTTP requests and responses

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Grump posted:

Does anyone have any suggestions for HTTP request interceptor software for Mac OS?

I'd like to be able to set breakpoints and edit both HTTP requests and responses

fiddler runs on mac now. https://www.telerik.com/fiddler

MrMoo
Sep 14, 2000

Isn't that what Postman is for?

teen phone cutie
Jun 18, 2012

last year i rewrote something awful from scratch because i hate myself
Not really. I want to gently caress with responses in the browser so I can test how UI renders.

I ended up buying a subscription to Charles. Fiddler’s Mac OS port sucks mongo dick

22 Eargesplitten
Oct 10, 2010



I have an ID that is getting a whole lot of poo poo in it. Like 15-20 lines. I feel like that might be hard to read. So I have two options here: break it into multiple parts, or just add spacing. You can't use multiple IDs on a single element in HTML. Is there a way to sort of encapsulate two IDs in one so I can break it out like I would functions in a C-based language, or should I just use spacing in the huge ID to fix it? These are both unique styles to the element, so I feel like using classes wouldn't be a good practice.

Disclosure: This is the first thing I've done outside of projects in Lynda courses.

YO MAMA HEAD
Sep 11, 2007

Do you mean that the element's ID is 20 lines long? Why?

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

22 Eargesplitten posted:

I have an ID that is getting a whole lot of poo poo in it. Like 15-20 lines. I feel like that might be hard to read. So I have two options here: break it into multiple parts, or just add spacing. You can't use multiple IDs on a single element in HTML. Is there a way to sort of encapsulate two IDs in one so I can break it out like I would functions in a C-based language, or should I just use spacing in the huge ID to fix it? These are both unique styles to the element, so I feel like using classes wouldn't be a good practice.

Disclosure: This is the first thing I've done outside of projects in Lynda courses.

I think the actual issue here is what you think an ID is for in HTML. Tell us what you are trying to accomplish, as an ID that's more an a single short string is not a thing that should be happening.

bigmandan
Sep 11, 2001

lol internet
College Slice
You should probably be using data-* attributes.

HTML code:
<span 
    id="something_unique"
    data-user-id="1234"
    data-group-id="4321">
Content Goes Here
</span>

22 Eargesplitten
Oct 10, 2010



I meant the body of the ID is 20 lines long. I ended up having to turn it into two elements anyway, couldn't get one to do both. So I split it into two IDs and one's on a child element now. My impression was that IDs were good to use where you could use a class but it's a one-off, so you won't have to re-use it. Is that not right? It's entirely possible I misunderstood those videos.

Not sure what's going on with the data-* attribute stuff. The Lynda courses didn't cover that yet :shrug:

Or it did and I forgot it because my memory is absolute poo poo.

I was doing an image with text over it, but I needed it to follow the standard flow while still having the text centered both vertically and horizontally. So I used display: table-cell, but then I couldn't get it to align without a bunch of manual adjustments and since my wife is going to be using this as a template for her other stuff in the future I want to keep it as simple as possible. She cargo cult self-taught herself over the past 10+ years, and it shows. Who the gently caress still uses <center>? There were also a ton of overrides where she would define stuff like height twice in the CSS, and then define it again in the HTML. Don't get me wrong, as you can tell I know next to nothing about HTML/CSS/Javascript, but I've got a C++/Java/C# background from school so I get why stuff is bad. I just don't know how to make it better without a lot of work.

I think it might actually be best to just set up a flexbox layout from scratch rather than trying to fix her code. OTOH, she doesn't know flexbox at all so that might be confusing for her.

The Dave
Sep 9, 2003

22 Eargesplitten posted:

I meant the body of the ID is 20 lines long. I ended up having to turn it into two elements anyway, couldn't get one to do both. So I split it into two IDs and one's on a child element now. My impression was that IDs were good to use where you could use a class but it's a one-off, so you won't have to re-use it. Is that not right? It's entirely possible I misunderstood those videos.

Not sure what's going on with the data-* attribute stuff. The Lynda courses didn't cover that yet :shrug:

Or it did and I forgot it because my memory is absolute poo poo.

I was doing an image with text over it, but I needed it to follow the standard flow while still having the text centered both vertically and horizontally. So I used display: table-cell, but then I couldn't get it to align without a bunch of manual adjustments and since my wife is going to be using this as a template for her other stuff in the future I want to keep it as simple as possible. She cargo cult self-taught herself over the past 10+ years, and it shows. Who the gently caress still uses <center>? There were also a ton of overrides where she would define stuff like height twice in the CSS, and then define it again in the HTML. Don't get me wrong, as you can tell I know next to nothing about HTML/CSS/Javascript, but I've got a C++/Java/C# background from school so I get why stuff is bad. I just don't know how to make it better without a lot of work.

I think it might actually be best to just set up a flexbox layout from scratch rather than trying to fix her code. OTOH, she doesn't know flexbox at all so that might be confusing for her.


Wow there's a lot going on here. Could you just post your code and what you're trying to accomplish? Maybe drag another loved one in that post too.

kedo
Nov 27, 2007

FWIW in most cases front end devs use classes for visual styles and IDs for JS as it keeps things nice and orderly. IDs are generally only used for styles in very specific cases.

That doesn’t mean you can’t or shouldn’t use IDs for styles, it’s just not that common anymore these days.

Tei
Feb 19, 2011

I learned ASM before I learned C, so maybe I can help.

ID's are unique, and like all in HTML, are supposed to be human readable. Something like id="ADF00-0111-4544-3455-FEFE" even if is valid (don't make me check if "-" is valid for ids, I think it is) is not a good ID, because it says nothing about the intention of the ID.

What you should do, and must do, is make valid clear concise id's that are unique. id="potato_bottle"

You would not use ADF00-0111-4544-3455-FEFE has a variable in C. Id's are not data, are code to be read by humans.

Somebody told you about using data-* attributes. That is a good way to add extra information to a tag withouth overloading existing attributes with more payload that is intended by the language design.

we want to see your code

Data Graham
Dec 28, 2009

📈📊🍪😋



Seriously, im like :suspense: here

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Data Graham posted:

Seriously, im like :suspense: here

This with a large side of :yikes:

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



I once inherited a templating system that just shoved the whole page and metadata into the IDs of DIVs in a pipe delimited format, so the code that showed the 'page' with a server-side ID of 123456 would work like

JavaScript code:
var content = $('div[id^=123456]')[0].id.split('|');
$('#main-element').html(content[3]);
window.title = content[2];
//etc
Several KB of JS in there, too.

"It's kinda slow on phones, but it works" - in TYOOLS 2011

Tei
Feb 19, 2011

My personal dream is to create something like a "Code Zoo" website where weird code and weird ideas would be show to scare/amaze/craze people.

Every year I feel the urge to put time on that, but them a new videogame is released that capture all my free time. I miss when I was teenager and it was possible for me to write code until 2:45 am, then do whatever society require from me the next day, no problem.

https://www.youtube.com/watch?v=2LhaXf3iTHo

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Tei posted:

My personal dream is to create something like a "Code Zoo" website where weird code and weird ideas would be show to scare/amaze/craze people.



This already exists though.

Tei
Feb 19, 2011


Github is more like a safari park. The good mixed with the bad. Please don't abandon the safety of your vehicles.

Seriusly, Github is just another forum. If what you find there is wrong and you still use it, is your fault.
No difference from a Stackoverflow discussion where the correct answers are near the bottom of the page, and the top answer is from a guy that know how to game the system.

What I am saying is Github is not has bad has you imply.

Tei fucked around with this message at 16:33 on Sep 28, 2018

22 Eargesplitten
Oct 10, 2010



kedo posted:

FWIW in most cases front end devs use classes for visual styles and IDs for JS as it keeps things nice and orderly. IDs are generally only used for styles in very specific cases.

That doesn’t mean you can’t or shouldn’t use IDs for styles, it’s just not that common anymore these days.

Ah, okay. I’ll switch to doing it that way.

I didn’t expect this strong of a reaction from everyone else. I guess it is pretty weird.

For what it’s worth, I’m not trying to poo poo on my wife. She’s not a programmer, she has no interest in programming. She’s an artist, and just puts stuff together to make layouts show up on community webpages.

Once I have access to the jsfiddle I can copy it in so you see what I started with.

I think probably the best idea is to start from scratch so I don’t get tripped up with weird stuff.

geeves
Sep 16, 2004

Tei posted:

Github is more like a safari park. The good mixed with the bad. Please don't abandon the safety of your vehicles.

Ah, now eventually you do plan to have good code on your, on your code tour, right? Hello?

Tei
Feb 19, 2011

Is only a dream, and will never be a real thing.

Tei fucked around with this message at 14:13 on Oct 1, 2018

Data Graham
Dec 28, 2009

📈📊🍪😋



Must code faster. Must code faster

kedo
Nov 27, 2007

If I may... Um, I'll tell you the problem with copying and pasting code from Stack Overflow, it doesn't require any discipline to attain it. You read what others had done and you took the next step. You didn't earn the knowledge for yourselves, so you don't take any responsibility for it. You stood on the shoulders of geniuses to accomplish something as fast as you could, and before you even knew what you had, you patented it, and packaged it, and slapped it on a plastic lunchbox, and now [bangs on table] you're selling it, you wanna sell it.

Tei
Feb 19, 2011

kedo posted:

If I may... Um, I'll tell you the problem with copying and pasting code from Stack Overflow, it doesn't require any discipline to attain it. You read what others had done and you took the next step. You didn't earn the knowledge for yourselves, so you don't take any responsibility for it. You stood on the shoulders of geniuses to accomplish something as fast as you could, and before you even knew what you had, you patented it, and packaged it, and slapped it on a plastic lunchbox, and now [bangs on table] you're selling it, you wanna sell it.

When I find a error message and I don't know what to do, I put it on the google box, then that sometimes end in Stackoverflow where I can see I am not the only one with the error. What others have tried. What have worked. Thats a lot, really.

When you are doing something pretty new, fresh or different, and you have a problem and you google, and absolutely nobody is talking about it, you are hosed.
The lack of good public debate about bugs is a reason to not buy closed source products, even if they looks like have a lot of support and quality.

Tei fucked around with this message at 14:21 on Oct 1, 2018

The Dave
Sep 9, 2003

There’s nothing wrong with googling an error, finding out the cause, and typing out the solution yourself.

Highlighting solutions and copy/pasting them is a sign you’re not interested in really understanding the solution.

Tei
Feb 19, 2011

The Dave posted:

There’s nothing wrong with googling an error, finding out the cause, and typing out the solution yourself.

Highlighting solutions and copy/pasting them is a sign you’re not interested in really understanding the solution.

The act of copying and pasting, I think theres nothing wrong with it.

Is failing to achieve "good practices" that is bad, IMHO, like adding unnecesary dependencies, changing the code style, or (the important one) adding code you yourself don't understand.

PT6A
Jan 5, 2006

Public school teachers are callous dictators who won't lift a finger to stop children from peeing in my plane
As long as you read and understand what the solution is doing, the mechanics of getting it into your own code are irrelevant. Typing it manually may help you ensure you actually understand what's going on, but there are other ways to do that too.

Cyber Sandwich
Nov 16, 2011

Now, Digital!

Tei posted:

My personal dream is to create something like a "Code Zoo" website where weird code and weird ideas would be show to scare/amaze/craze people.

https://www.youtube.com/watch?v=2LhaXf3iTHo

Do it. I'll read it.

http://thedailywtf.com/ has some great reads but doesn't cover only web design. Pairs well with my morning coffee.

I'm also interested in this HTML ID business, though. I need closure.

Sab669
Sep 24, 2009

So I'm working on an ASP.NET MVC application that just uses jquery and the KendoUI controls. I have a table with two dozen rows, and 4 columns per row. The first column is just some label text and then the next 3 columns are textboxes. When you press Tab, the control focus moves down to the next row but stays in whatever column you're in.

A user reported a bug yesterday that pressing the Enter key moves focus horizontally, rather than vertically, which is not what we want. I didn't even know you could press Enter to change focus :v: I've tried Googling around to figure out this issue, but unfortunately searching for things like "enter changes focus" just gives me results for people who want to make it so that when you press Enter it will change tab focus. My software's already doing this, but it doesn't respect the tab order.

Here's one row from the .cshtml file:

code:
<tr>
	<td>
		I. 	Walk 10 feet
	</td>
	<td class="qicolumn-width-60 textalign-left valign-top">
		@(Html.Kendo().TextBoxFor(m => m.V14_GG0170I).HtmlAttributes(new { id = "cmbV2_GG0170I", @class = "k-dropdown-width-30", @tabIndex = "45", style = "width:60px", @maxlength = "2", @onKeyUp = "ValidateValues(this)", @onBlur = "ValidateValues(this, null, 'blur' );OnChangeGG170I1(this)" }))
	</td>
	<td class="qicolumn-width-60 textalign-left valign-top">
		@(Html.Kendo().TextBoxFor(m => m.V14_GG0170IGoal).HtmlAttributes(new { id = "cmbV2_GG0170IGoal", @class = "k-dropdown-width-30", @tabIndex = "72", style = "width:60px", @maxlength = "2", @onKeyUp = "ValidateValues(this, true)", @onBlur = "ValidateValues(this, true, 'blur' )" }))
	</td>
	<td class="qicolumn-width-60 textalign-left valign-top">
		@(Html.Kendo().TextBoxFor(m => m.V14_GG0170IDischarge).HtmlAttributes(new { id = "cmbV2_GG0170IDischarge", @class = "k-dropdown-width-30", @tabIndex = "97", style = "width:60px", @maxlength = "2", @onKeyUp = "ValidateValues(this)", @onBlur = "ValidateValues(this, null, 'blur' );OnChangeGG170IDischarge(this)" }))
	</td>
</tr>
The row of controls after this have the tab indices of 46, 73, 98 - so in theory Enter should focus the correct, next tab, right? I'm sure the answer is probably, "Don't use tables for your layout" and you're 100% right, but I don't have the time to fix that :(

All I could find in Kendo's documentation was this tiny section about keyboard navigation but I don't know how to fix my issue.

So, anyone know why the Enter key doesn't respect tab index?

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


That's not the browser doing it, browsers treat an enter key press as a form submission. I'd check the KendoUI settings.
Or all your inputs have the required attribute and the browser is just putting focus on the first empty one it finds.

FateFree
Nov 14, 2003

I am building an application that generates an html report by connecting to an appliance on a network. The connection is made through a JSON web service, but the appliance is not exposed publically over the internet. So the original idea was to deploy a Java JAR file that users double click, it prompts them for the IP of the appliance and a user/pass, then it generates the report and displays it in a browser. This works but it requires distributing this JAR file which is annoying. I would love to just deploy this code on a regular server, but the server can't reach the appliances.

So my question: Can I extract the code that makes the api call to client side javascript, and just forward that data to the report generator on the server through a form submit or something? It would basically use the user's browser as a proxy to talk to the appliance and then send the data to the server. I don't see why this wouldn't work unless there is some sort of restriction on the client side javascript.. is this easier than I am expecting?

EDIT: Let me complicate things and mention that the JAR file has a self signing cert to get around any SSL connection issues. So the client side JS would need to do that too.

FateFree fucked around with this message at 12:15 on Oct 16, 2018

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

FateFree posted:

I am building an application that generates an html report by connecting to an appliance on a network. The connection is made through a JSON web service, but the appliance is not exposed publically over the internet. So the original idea was to deploy a Java JAR file that users double click, it prompts them for the IP of the appliance and a user/pass, then it generates the report and displays it in a browser. This works but it requires distributing this JAR file which is annoying. I would love to just deploy this code on a regular server, but the server can't reach the appliances.

So my question: Can I extract the code that makes the api call to client side javascript, and just forward that data to the report generator on the server through a form submit or something? It would basically use the user's browser as a proxy to talk to the appliance and then send the data to the server. I don't see why this wouldn't work unless there is some sort of restriction on the client side javascript.. is this easier than I am expecting?

EDIT: Let me complicate things and mention that the JAR file has a self signing cert to get around any SSL connection issues. So the client side JS would need to do that too.
Up until the cert part, it was all doable easily. :smith:

Tei
Feb 19, 2011

Ajax calls to random servers are nasty and may need the served provide custom headers (cors?) or to the request to originate from the machine that is asking (the html is hosted by the apliance).

This limitations exist because among other things, malware guys where abusing crappy routers by uploading a custom firmware or change the dns settings or other evil things.

Using the browser has proxy have big problems if you dont control all parts.

https://stackoverflow.com/questions/5750696/how-to-get-a-cross-origin-resource-sharing-cors-post-request-working


If you can host html in the appliance, everything is much easier. That html can query the appliance (same host, so no problem), then send the information to your server with whatever way you want.

Tei fucked around with this message at 13:17 on Oct 16, 2018

LLSix
Jan 20, 2010

The real power behind countless overlords

Two of my coworkers are claiming that a recent change to IE's implementation of document.querySelector & element.querySelector for Javascript (JScript\ECMA) is causing issues. Does Microsoft maintain a public changelog of their implementation or anything else I can check to see if there has actually been a change there?

On the off chance this is real and someone else has run into it, they're claiming that changing from
code:
document.querySelector("#notetext")
to
code:
document.querySelector("textarea#notetext")
got IE to start returning <textarea id='notetext' ... >...</textarea> again after it mysteriously started returning NULL.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

LLSix posted:

Two of my coworkers are claiming that a recent change to IE's implementation of document.querySelector & element.querySelector for Javascript (JScript\ECMA) is causing issues. Does Microsoft maintain a public changelog of their implementation or anything else I can check to see if there has actually been a change there?

On the off chance this is real and someone else has run into it, they're claiming that changing from
code:
document.querySelector("#notetext")
to
code:
document.querySelector("textarea#notetext")
got IE to start returning <textarea id='notetext' ... >...</textarea> again after it mysteriously started returning NULL.

https://developer.microsoft.com/en-us/microsoft-edge/platform/changelog/ maybe?

Tei
Feb 19, 2011

LLSix posted:

got IE to start returning <textarea id='notetext' ... >...</textarea> again after it mysteriously started returning NULL.

are they sure id="notetext" is not duplicated?

maybe they have not changed the method normal operation, but changed how it behave with a malformed document

Rand Ecliptic
May 23, 2003

Jesus Saves! - And Takes Half Damage!!
I posted this in the JavaScript thread, but this might be a more appropriate place:

I'm new to programming and for my class we're using Moment.js and Firebase to create a train scheduler (seems to be a fairly common project). The user is supposed to enter data on when the first train departs and the frequency of the train's arrival and Moment.js should calculate when the next train will arrive and how many minutes away it is.

My code isn't working however. The calculated data isn't appending properly into the table. Can anyone take a look and see what the problem is for me? It would be much appreciated.

Link to the GitHub repository: https://github.com/PaulKlein22/train-schedule

Many thanks in advance.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Rand Ecliptic posted:

I posted this in the JavaScript thread, but this might be a more appropriate place:

I'm new to programming and for my class we're using Moment.js and Firebase to create a train scheduler (seems to be a fairly common project). The user is supposed to enter data on when the first train departs and the frequency of the train's arrival and Moment.js should calculate when the next train will arrive and how many minutes away it is.

My code isn't working however. The calculated data isn't appending properly into the table. Can anyone take a look and see what the problem is for me? It would be much appreciated.

Link to the GitHub repository: https://github.com/PaulKlein22/train-schedule

Many thanks in advance.

What does the error console say when you run the code? Breakpoint things and see if variables are what you think they are. At first quick glance, it looks like you are using some undefined variables in your firebase new child listener.

Adbot
ADBOT LOVES YOU

Rand Ecliptic
May 23, 2003

Jesus Saves! - And Takes Half Damage!!
Thanks for looking! When I open the console I don't get any errors. The only variable that seems to be undefined is currentTime, but I'm not sure what I should be doing with it. I have it set to moment(), which is being used elsewhere.

The issues I'm seeing are that minutesAway is coming back as NaN and nextTrain looks like it's just displaying the current time. It should be calculating when the next train to arrive will be, based on the current time, the time of the first train, and the frequency of the arrivals.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply