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
9-Volt Assault
Jan 27, 2007

Beter twee tetten in de hand dan tien op de vlucht.

stoops posted:

I don't know much javascript or jquery. I mean, I can modify and get things to work, but i'm not comfortable writing it from scratch.

Does anyone have any great solid teaching resources? I don't mind paying for video tutorials, or online classes.

I can't seem to find any community college scripting programs, and i figured the net is the best way to go about it.

if any are highly recommended, I'd appreciate.

http://javascriptissexy.com/how-to-learn-javascript-properly

Adbot
ADBOT LOVES YOU

9-Volt Assault
Jan 27, 2007

Beter twee tetten in de hand dan tien op de vlucht.
D3.js question:

If i do:
code:
    <script type="text/javascript">
  var dataset;
  d3.csv("spanish-silver.csv", function(error, data) {
    if (error) {
      console.log(error);
    } else
      {console.log(data);
        dataset = data;
      };

});



d3.select("body").selectAll("p")
    .data(dataset)
    .enter()
    .append("p")
    .text("hail satan!");

</script>

i get an empty page and an error message stating "Uncaught TypeError: Cannot read property 'length' of undefined", however the csv gets loaded based on the console output.

If i wrap the second part in a function and call that function it works, printing a bunch of hail satan paragraphs:

code:
    <script type="text/javascript">
	var dataset;
	d3.csv("spanish-silver.csv", function(data) {
      dataset = data;
      satan(dataset);
 	});



	var satan = function(dataset) {d3.select("body").selectAll("p")
		.data(dataset)
		.enter()
		.append("p")
		.text("hail satan");};

</script>
Why is the second example working, but the first not? Im quite clueless about javascript so i should probably learn more about it. :shobon:

9-Volt Assault
Jan 27, 2007

Beter twee tetten in de hand dan tien op de vlucht.
i have a simple div:

code:
   
<div id="clock">
<span id="minutes">00</span> : <span id="seconds">00</span>
</div>
and i want to replace the value of the id's minutes and seconds with a variable using jQuery.

If i do

code:
$('#clock').text(workTime)
it works just fine, but replaces everything.


If i do
code:
$('#minutes').text(workTime)
nothing happens.

I also tried using plain javascript, but if i do
code:
document.getElementById("seconds").innerHTML= String(workTime)
i get a "Cannot set property 'innerHTML' of null" error.

Clearly im doing something wrong with the spans, but i cannot figure it out. :confused:

9-Volt Assault
Jan 27, 2007

Beter twee tetten in de hand dan tien op de vlucht.

Clark Nova posted:

With both jQuery and DOM, it looks like it can't find elements with the IDs "minutes" and "seconds." If you use $.text() or $.html() on a parent, it'll wipe out everything inside it, and you'll have to reload to get them back.

Ah, this explains what is happening. I set an initial time value at the parent level before allowing to change it. If i remove that part it all works like i wanted it to.

Thank you and also Kekekela for looking into it! This wasnt how i would have expected it all to work, so it was a good lesson to learn.

9-Volt Assault
Jan 27, 2007

Beter twee tetten in de hand dan tien op de vlucht.

Skandranon posted:

Yes, that's a cute answer. I'd then ask you to write out _.isEqual().

Lol if you expect your developers to copy existing functionality for the sake of it.

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