HighDots Forums  

A Beginner's questions

Javascript JavaScript language (comp.lang.javascript)


Discuss A Beginner's questions in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
SAM
 
Posts: n/a

Default Re: A Beginner's questions - 02-03-2008 , 04:37 PM






sheldonlg a écrit :
Quote:
I do not know much javascript. I know php and Java and other things. In
a project that I am on there is Javascript that I have to modify as part
of an overall task. Basically, what I am asking is for someone to tell
me what the following means.

As an example, in the html code there is a line:

li id=“MenuReview” onclick=“menuGetSubmenu(event, this);”>Review</li

for a menu item that contains submenus. I assume that the "this" refers
to the id of the <li>, or “MenuReview”.
Yes 'this' means this (element) that's to say here the tag LI

Quote:
What does "event" refer to? It
gets passed into menuGetSubmenu.
'event' refers to event, here the event is the JS function : onclick

Quote:
The first number of lines of menuGetSubmenu are:

function menuGetSubmenu(evt, menuItem)
{
e = evt || window.event;
menuItem = menuItem || this;
Because IE doesn't analyze events placed in the page as other browsers ...

One has its elements that will send the element's event
an other will look at what in the page fires the event (from the window)

Well, one will send a reference to itself, the other a reference
relatively to the window object.

in the function the argument is called (named ?) evt
menuGetSubmenu(evt, menuItem)

On first line we will try to catch the event
e = evt || window.event;
e will be evt (the argument of the function)
and if doesn't exist (because not sent by this or that browser)
it will be the window.event (you know : looking at complete page)

so when you do :
onclick="truc( event, this);"
'event' here is the JS name used by this browser who needs it to refer
to the target (the element who has the event), this event will fire when
clicking (onclick) and will report all what was made on this instant
(ie: pressed key(s), coordinates ...)
Remember this other browser doesn't needs this 'event' there in argument
(but all is seen too).

Further in the function you can use 'this'
(which is argument 'menuItem' of the function)
menuItem is now the entire LI (the 2 tags and what is between them)
that's to say the DOM element.

Quote:
Next, what is "this" in the function? What is happening here? The
MenuItem is obviously MenuReview in this example,
No, 'MenuReview' is the ID of 'this', of the LI ('this' = 'menuItem')


Quote:
Another, separate question, is that I have come across <a
href="javascript:void(0);>...</a>. What does this do?
void(0) = do nothing

it is a very bad way to do to stop (block?) a link

<a href="myPage.htm" onclick="return truc(this);">example</a>

<script type="text/javascript">
function truc(what) {
alert('link to the page :\n' + what.href);
alert('text of link = ' + what.innerHTML);
return false;
}
</script>

The function will return false and by that will break the link.
If JS is disabled, the page can load.

--
sm


Reply With Quote
  #12  
Old   
SAM
 
Posts: n/a

Default Re: A Beginner's questions - 02-03-2008 , 05:04 PM






sheldonlg a écrit :
Quote:
VK wrote:
On Feb 3, 2:26 am, sheldonlg <sheldonlg> wrote:
As an example, in the html code there is a line:

li id="MenuReview" onclick="menuGetSubmenu(event, this);">Review</li

I wouldn't use smart quotes in HTML source - can be troublesome
sometimes. It is better to stick to "double quotes" for HTML
attributes and 'single quotes' for Javascript strings. Easier to
maintain and much lesser risk to run into nested quotes problem.

They are actually double quotes in the code. What showed up here was
the result of cut-and-paste processing. My coding technique is to use
either single or double when it doesn't make a difference and to use
single to enclose a double or double to enclose a single.
I allways use double quotes.

Except some times when it is the PHP who make (write) the html code.
(because it is easier to do).

Quote:
I should have said "the element
with the id specified in <li>, or 'MenuReview'".
.... yes and no ... 'this' is the element, no less, no more.
(from opening tag to closing one)

Quote:
Is "event" some form of reserved keyword?
that is

Quote:
It appears in the call
sequence onclick="menuGetSubmenu(event, this);", and I don't see where
it would get it from unless "event" is reserved to take on the type of
event. in this case "onClick". So, where does "event" get defined?
event is the reserved JS word for all what happens when an event fires
(one word for 2 things)
(it is much more easy to explain it in french for instance where we can
talk of 'event' differently : 'evennement' = what's happen / 'event' =
the javascript)

Quote:
This statement leads me to believe that my supposition just above is
correct and evt (which comes from event) refers to the onClick event.
yes and no ... the onclick fires the event report
- object clicked and by the way
- object's place
- object's attributes
- object's content
- and so on
- all what happen on this instant
- pressed key(s)
- etc
the evt of the function receives it
(is it exists, if not : window.event)


--
sm


Reply With Quote
  #13  
Old   
SAM
 
Posts: n/a

Default Re: A Beginner's questions - 02-03-2008 , 05:10 PM



Thomas 'PointedEars' Lahn a écrit :
Quote:
VK wrote:
[...] Thomas 'PointedEars' Lahn [...] wrote:
So you should have simply refrained from posting about them which would
have spared this newsgroup another load of your nonsense and FUD.
Thomas, with however little you know about Javascript and DOM
programming, [...]

ROTFL. You are confusing me with someone else, probably yourself.
Y avait longtemps ... !

Please could you both put a signal or something in the post's subject
when you take(bring) out your swords?

--
sm


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.