Posts

Showing posts from April, 2019

Javascript array and changing an image with button

Javascript: iteration to change images in DOM Purpose: For the next experiment, it was trying to change an image by button click, and surf through the array in my javascript file. Setup: Remember all files are in the same folder. To replicate this experiment locally on your browser, have your image files, your HTML and your JS in the same folder, replace the file names in the image_array [] with your file names.  In my code, you'll see the image paths for my images. Double click that index.html file and see the code run.  *Note about frameworks and non-local use of this code* In an actual web app, with something like Django, the images would be in static / images,  the html, in templates, and the javascript in the static/js. But why? It's helpful to me to create these little projects so I can explore how things work. I'm sharing as I learn so that maybe this method would be useful to others.  Notes Next experiment I will evolve the style more, and try to retrieve the i

Simple setInterval Javascript HTML interaction test

Image
Using the method from the previous post: https://camelcasenoodles.blogspot.com/2019/04/a-simple-way-to-test-some-javascript.html I have made these two files to try out the 'setInterval' in JavaScript. picture of simple counter in a grey HTML page: I left the 'alerts' in the functions.  If I'm not sure if a function is being called, I can un-comment the alert, and see if I had an error that is preventing the function from being called. (I had G etElementById  instead of g etElementById   &&  HTML will ignore anything it can't read  *I'll look this up one day soon to confirm* )  No alert, the function is not being called. Break it, modify it, experiment.  May the spam be ever in your flavor. ***********  HTML  ********************** <!DOCTYPE html> <html> <head> <title>Exercise 1</title> <!-- your src will be different from mine.  see previous blog post linked at top -->  <script type=

A simple way to test some javascript

Image
Not too long ago I set up an entire Django app just for testing out my JavaScript interactions. Just this morning I realized I didn't have to do any of that. Simply create a folder, ( I did it on my desktop directory) and put your html, and referenced javascript in the same folder. To run the html file, all you have to do is double click it, The computer will run the HTML file through your default internet browser. As long as your path to the javascript file is correct in your HTML <script> tag that is located in the header, your javascript should run.  You can also change code and refresh the page on demand.   Why I didn't know this sooner is kinda irritating.  So if your looking for a simple way to do this, and stumble across my blog post, maybe this is for you. Example code below.  --May the spam be ever in your flavor -- <!--           The HTML    -->  <!DOCTYPE html> <html> <head> <title> will it work? </title&g