GET A Random Number BETWEEN:

and
 

Number:

 
  • Click me -> onclick.
  • Click me -> click event.
  • Click me calling function.

Activate: onclick and click event.

Result:  

Inspired by Chris Coyiers - Generate a Random Number

So first at all ... I had some problems with JavaScript. The code was not working, but why? I had to learn about the difference in JQuery and pure Javascript! Some people are call it "JavaScript" but what they are using is "JQuery". If the website does not support it, you will fail using it. The same for HAML, SCSS or SASS. 

My personal preferences for tests are: nothing else than an empty text file, filled up with code. This will bring the truth to the screen. If standard browser code is used, it will work, otherwise it fails. It is often a real challenge, to bring it to work.

Prolems within this example were:

  • The click event was not working. The reason: JavaScript had to be activated first. I solved it with 'onload=...' either on the <body> tag or on a picture inside the <img> tag. Because it's Drupal and I have no access to the body tag without to alter the theme, a small picture was inserted.
  • But first I had to figure it out - with the help of a second button and function to generate the values, calling the function directly.
  • I created a couple of buttons as a list, to test the funcionality of the click event. The Activate-button is obsolete, but I left it for documentation.
  • The last task was to change the color of editet values in the input boxes. Because JQuery is not working, I had to find a different solution in pure JavaScript. The challenge was: not to use an individual event for every input box, but for all together. The problem was: to figure out, which boxes were have been changed.