473,396 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

object.onmouseover

HI All,

Is it possible to do the following?

object = document.getelementById('something');

object.onmouseover='alert("hi");';

...................
I know that object.onmouseover=function(){alert("hi");} is OK but I
want to do it the first way. Can it be done?

Graham
Jun 27 '08 #1
3 4167
Laser Lips wrote:
object.onmouseover='alert("hi");';

..................
I know that object.onmouseover=function(){alert("hi");} is OK but I
want to do it the first way. Can it be done?
Assigning a function makes sense, assigning a string as you do does not
make sense. So it can be done but is not in any way useful. If you have
a string then you need to create a function from it:
object.onmouseover = new Function('alert("hi");');
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 27 '08 #2
Thats just what I needed thanks. :0)
Graham
Jun 27 '08 #3
Laser Lips escribió:
Is it possible to do the following?

object = document.getelementById('something');

object.onmouseover='alert("hi");';
[...]
I know that object.onmouseover=function(){alert("hi");} is OK but I
want to do it the first way. Can it be done?
Do you need to execute code from a string or is it just an aesthetics
question?

In the latter case, this is not HTML; you don't need to pack all your
code in one line. So (in my humble opinion) this looks just fine:

object.onmouseover = function(){
alert("hi");
};

You can also assign a named function:

function sayHi(){
alert("hi");
}

object.onmouseover = sayHi;
In the former case you'd have to do this:

object.onmouseover = function(){
eval('alert("hi");');
};

Not a good idea unless there's powerful reason.
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: marius | last post by:
i get "name_ is undefined" error. how should i access ClassA object from inside this inner function/object? in Java i would write something like this alert(ClassA.this.name_) <html> <head>...
10
by: Steve Benson | last post by:
Our regular programmer moved on. I'm almost clueless in Javascript/ASP and got the job of adapting existing code. In the page below, everything works until I added the function checkIt() to...
1
by: Charlie T | last post by:
Hello, This is somewhat of an easy task in other languages, but for some reason I can't figure it out in JavaScript. I have a function "getData( )" The function will be contained in side of a...
4
by: Greg | last post by:
I'm guessing the problem I'm having has something to do with Master Pages or DetailsView because the exact same code works fine on a page without a Master Page and DetailsView controls. The...
28
by: ensemble | last post by:
I'm trying to utilized a more object-oriented approach to managing window events in javascript. Thus, I am creating a "controller" object to handle events and interact with the server. However, I...
1
by: semidivine | last post by:
I'm a real amateur when it comes to javascript... I've been around it for years and played with it, but I've mostly used borrowed scripts. This one was posted on the web for a menu dropdown. It works...
1
by: finizaini | last post by:
I'm receiving an "Object Expected" Error (Line:309, Char:0). I'm confused as to what is happening.Also, I can't run this code using other browser such as Fire Fox. Thispage only can view using IE....
3
by: suganya | last post by:
Hi Some professionals already has developed the project using menu. In my company, they have given me task to clear the error in that. It is a script file named as "menubarAPI4.js" which is kept...
2
by: tridirk | last post by:
Hi; I am getting a Objceted Expected Error on my forum site. I can't find what is wrong? Line: Char: Error: Object expected Code:0 the site is My SMF Forum
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.