Best JavaScript Book : http://goo.gl/zodRHD
I teach you how to monitor events and react to them dynamically in this JavaScript Video Tutorial. Create Inline JavaScript : Change CSS Styling : Change Any Element Dynamically : Monitor Everything the User Does : Tons More!!!
Code is Here: http://bit.ly/fNbPwZ
Original source
43 responses to “JavaScript Video Tutorial Pt 2”
changing the width resizes the picture, but not changing the height. I didn't misspell the statement. What could be the problem?
I can't get the brain image to appear. I have it in the same folder as my code. Any help would be appreciated.
How do you provide Event Listeners for only a part of a website? What if I only want a listener to apply to a div tag and not the whole website?
What did i do wrong with the mouse movement detection??????
<!DOCTYPE html>
<html>
<head>
<title>Javascript tutorial</title>
</head>
<body>
<noscript>
<h3>This site requires JavaScript</h3>
</noscript>
<form name="formex">
<p>Text input</p>
<input type="text" name="mousex" />Mouse X Position<br />
<input type="text" name="mousey" />Mouse Y Position<br />
</form>
<script language="javascript" type="text/javascript">
var mie = (navigator.appName == "Microsoft Internet Explorer")?true:false;
if (!mie)
{
document.captureEvent(Event.MOUSEMOVE);
document.captureEvent(Event.MOUSEDOWN);
}
document.onmousemove = mousePos();
document.onmousedown = mouseClicked();
var mouseClick = 0;
var keyClicked = 0;
var mouseX = 0;
var mouseY = 0;
function mousePos(e)
{
if (!mie)
{
mouseX = e.pageX;
mouseY = e.pageY;
}
else
{
mouseX = event.clientX + document.body.scrollLeft;
mouseY = event.clientY + document.body.scrollTop;
}
document.formex.mousex.value = mouseX;
document.formex.mousey.value = mouseY;
return true;
}
</script>
Thanks for these tutorials!!!!! I have taken 2 online classes but with deadlines, I feel like I only learned js for the homework assignments.
Can you go over the mouse sex part again? Thanks.
HI Derek – I see this too .. very good 🙂 ' i ask again if you can attach the files
why you return true in every function?
You're awesome!
Mouse tracking isn't working for me. Whats up wit dat. Everything else worked wonderfully. Thanks for your tutorials Derek.
<form name="formex2">
<p>formex2 right below</p>
<input type="text" name="mousex" />Mouse X position<br />
<input type="text" name="mousey" />Mouse Y position<br />
</form>
var mie = (navigator.appName == "microsoft IE")?true:false;
if (!mie)
{
document.captureEvents(Event.MOUSEMOVE);
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousemove = mousePos();
document.onmousedown = mouseClicked();
var mouseClick = 0;
var keyClicked = 0;
var mouseX = 0;
var mouseY = 0;
function mousePos(e)
{
if (!mie)
{
mouseX = e.pageX;
mouseY = e.pageY;
}
else
{
mouseX = event.clientX + document.body.scrollLeft;
mouseY = event.clientY + document.body.scrollTop;
}
document.formex2.mousex.value = mouseX;
document.formex2.mousey.value = mouseY;
return true;
}
Another great video! Thanks again.
Why can't I download this part 2, pls do something about it
if I'm lazy, should I ironically enough learn coffescript so that javascript isn't such a pain to write? I already started with pug and sass for that very reason.
Love the way you get to the point in every tutorial you make. I'm tired of watching tutorials that drag on and on never getting to the point. Great job Derek, you're awesome! 🙂
In my case document.littlebrain yields 'undefined' result (5:10), was this element access style dismantled since 2011 or am I missing somthing?
I've had to work around, tweaked onClick event this way:
onClick="alertme(this);"
and alertme function respectively:
function alertme(ele)
{
alertmsg = ele.src + "nHeight: " + ele.height + "nWidth: " + ele.width;
alert(alertmsg);
return true;
}
At 21:20 you can also access key value directly (in !mie):
keyClicked = e.key;
This will work
var mie=(navigator.appName=="Microsoft Internet Explorer")? true : false;
if(!mie)
document.captureEvents(Event.MOUSEMOVE);
document.onmousemove=mousePos;
var mouseX=0;
var mouseY=0;
function mousePos(e){
if(!mie){
mouseX=e.pageX;
mouseY=e.pageY;
}else{
mouseX=event.clientX+document.body.scrollLeft;
mouseY=event.clientY+document.body.scrollTop;
}
document.myform.mousex.value=mouseX;
document.myform.mousey.value=mouseY;
return true;
}
Hi Derek, I started learning JS and I am using your awesome tutorials. I was wondering if these concepts still apply as of today ?
what is the reason that you create a function called alertme() only for alertmsg ? i mean in my case without creating function
alertme working properly onDblclick('….') even in <p>
can explain it little more plz
in my case alertmsg doesn't work if i put the onClick="alertme()" or other , only work onClick="click()"
if i put the onClick="alertme()" or other it shows the image path and image height and width. what 's wrong with mine ?
it does not work
Very useful series. Interesting also trying to translate the same functionality into jQuery code.
Hi Derek, I have learned a lot from your videos can you create a tutorial on Kendo UI any time soon.
Pretty ease to understand especially in you have Java Programming experience.
I'm curious, why do we need to return true in functions such as alertme() and changeImage() ?? 🙂
Splitting up the videos like this is a great method, keep it up :). Still engaged lol.
Two questions:
1) Why is the semicolon appearing BEFORE the ending double quote in the function calls? Example: <img src="images/LittleBrain.png" id="littlebrain" onClick="alertme();" onDblClick="alert('You Double Clicked');"/>
2) Like many commenters, I could not get the alertme(); function to work. I changed it FROM document.littlebrain.src to littlebrain.src or document.getElementById("little brain").src Both changes worked. EXCEPT, now that single click works, now double click doesn't engage.
Please help.
Great!!
Thanks
750 000 people did not make it. Feel special already
+Derek Banas
Thanks!
is the semicolon necessary after the end of the function name in inline JS ?
Around 18:37 I noticed that for the MIE logic, instead of using the passed in "e" parameter that you updated later on you use "event". Is "event" a built in global variable? And is it used only for MIE or for all browsers? Thanks for making these videos btw, I find them to be the best online tutorials and I've tried other sources including CodeSchool and CodeAcademy
These are simply great for reference or reminder for JS. features maybe not so great for complete beginners and i thank you for conciseness
Question to the stage at 13:00:
By me if I load the site the <p> paragraphs are visible, and will only go hidden once I checked in and then out the checkbox. Why is the difference?
thanks in advance!
thank u!
why is it that you are able to refer to "littlebrain" in "alertme()" directly by object id but you need to use "getElementById" in "changeImage()"?
Is Corey Taylor doing this tutorial ? its either him or Mick Thomson
Great refresher!
unable to capture mouse positions.
also at time 19:16 there are brackets at document.onmousemove=mousePos();
and in the next frame , where did the brackets go ??
It's like document.onmousemove=mousePos;
you didn't remove the brackets , at least didnt show while removing them,
whatever you did , isn't working here, my code is exactly same as yours and I'm using google chrome.
also what is e ?
when you're calling mousePos()
you're not passing anything to it, and also you're calling a function without putting on parenthesis , mousePos.
I don't understand how this is working on your PC.
Great vid thank you!
at 20:30
document.onkeypress = keyPressed;
line 47 make sure there's an 's' on captureEvents
line 51 there's no () brackets after mousePos
freeze vid at 19:38 to see where code has been debugged
awesome stuff DB!!
Nice video 🙂 tnx only one thing :
– instead of document.littlebrain.src write: document.getElementById("littlebrain").src because without getElementById javascript doesn't know what element you want. Ofc you need document.getElementById("littlebrain").height and for width the same thing.