SitePoint Sponsor |
|
User Tag List
Results 1 to 8 of 8
Thread: Body onClick, Except
-
Jul 30, 2007, 16:13 #1
- Join Date
- Nov 2005
- Location
- Trinidad
- Posts
- 3,746
- Mentioned
- 45 Post(s)
- Tagged
- 0 Thread(s)
Body onClick, Except
Hi.
I have a simple drop down menu in a website.
It does the typical... opens onMouseOver, closes when the body is clicked.
<body onclick="resetDrawer();">
Is there some type of work-around to this??
Is there something like...
<body onclick, except when elementbyid = 'InputField'>
Trying to fill the unforgiving minute
with sixty seconds' worth of distance run.
Update on Sitepoint's Migration to Discourse
-
Jul 30, 2007, 18:01 #2
- Join Date
- Aug 2006
- Location
- Kansas City
- Posts
- 98
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
<body onclick="javascript:document.getElementById("txtField")? return false: MethodName();">
Just a shot in the dark
-
Jul 30, 2007, 18:34 #3
- Join Date
- Nov 2005
- Location
- Trinidad
- Posts
- 3,746
- Mentioned
- 45 Post(s)
- Tagged
- 0 Thread(s)
Didn't work.
I'm thinking now... is there a way to get the clicked item in a variable so I could have say...
Code JavaScript:If ($clickedItem != elementById('InputField') ) { Execute Reset }
??
Trying to fill the unforgiving minute
with sixty seconds' worth of distance run.
Update on Sitepoint's Migration to Discourse
-
Jul 30, 2007, 18:45 #4
- Join Date
- Aug 2006
- Location
- Kansas City
- Posts
- 98
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
function ResetDrawer()
{
if(!this.id == document.getElementByID("inputField"))
{
execute code
}
else
{
//invalid field
}
}
-
Jul 30, 2007, 20:31 #5
- Join Date
- Nov 2005
- Location
- Trinidad
- Posts
- 3,746
- Mentioned
- 45 Post(s)
- Tagged
- 0 Thread(s)
As a test I tried that out as follows...
Code JavaScript:function resetDrawerInit() { alert(this.id); if(this.id != document.getElementById('Drawer2_Articles')) { resetDrawer(); } }
...and the body onclick calls that new resetDrawerInit(); function.
It's not working, though, and I'm pretty sure it's because the "this" keyword is referring to the whole body rather than the specific object that is clicked.
The body tag is the one with the onclick, after all. No matter what, the body is the HTML element that's calling the function.
Thanks for the suggestions anyway.
Trying to fill the unforgiving minute
with sixty seconds' worth of distance run.
Update on Sitepoint's Migration to Discourse
-
Jul 30, 2007, 20:35 #6
- Join Date
- Nov 2005
- Location
- Trinidad
- Posts
- 3,746
- Mentioned
- 45 Post(s)
- Tagged
- 0 Thread(s)
Well... regarding above...
what's weird, though is that my open body tag now looks like...
Code HTML4Strict:<body id="Bob" onclick="resetDrawerInit();">
...so theoretically the alert in resetDrawerInit(); should say "Bob". In reality it says "undefined".
Maybe I'm just using the this keyword wrong.
Trying to fill the unforgiving minute
with sixty seconds' worth of distance run.
Update on Sitepoint's Migration to Discourse
-
Jul 30, 2007, 22:46 #7
- Join Date
- Sep 2005
- Location
- Sydney, NSW, Australia
- Posts
- 16,875
- Mentioned
- 25 Post(s)
- Tagged
- 1 Thread(s)
JavaScript event handlers in the body tag are attached to the window and not to the body.
Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">
-
Jul 31, 2007, 09:33 #8
- Join Date
- Nov 2005
- Location
- Trinidad
- Posts
- 3,746
- Mentioned
- 45 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by felgall
So then there's no way of detecting which object was clicked on like that then??...
because no matter what, "this" would refer to the window itself and not the individual clicked object. Yes??
Trying to fill the unforgiving minute
with sixty seconds' worth of distance run.
Update on Sitepoint's Migration to Discourse
Bookmarks