...

View Full Version : invoking Javascript function throws "Object expected", why?



atolymbek
06-19-2009, 02:03 AM
Friends,:confused:

My very simple function clickEvent1() (defined in the page head) that expands/shrinks a hidden tag <h6> with text, id="lignep" in the body

Here is a code which throws error for line 104 in the page body with message "Object expected", but I can't figure out what is wrong in this line that calls for function clickEvent1():

<h6 id="ligne"; onClick="clickEvent1()"; style="font-size: 12pt; line-height: 130%">

Thanks much!

AT;)

Here the page with Javascript in the title:
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:offic... xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<style>

h2
{margin-bottom:.0001pt;
text-align:center;
page-break-after:avoid;
border:medium none;
padding:0in;
font-size:16.0pt;
font-family:"Times New Roman";
margin-left:0in; margin-right:0in; margin-top:0in}
table.MsoNormalTable
{mso-style-parent:"";
font-size:10.0pt;
font-family:"Times New Roman"}

</style>

<script language="JavaScript">

alert("On va tester Expand and Collapse Text au moyen de tag1 = P et id = para");

function onMouseoverEvent()
{
alert("Alors commencons par testant si tag H3 est dans le texte");
{
var tag1, parentTag1;
tag1 = window.event.srcElement.tagName;
parentTag1 = window.event.srcElement.parentElement.ta...
if (tag1 == "H3" && parentTag1 == "BODY")
{
if (document.all(window.event.srcElement.id + "p").style.display == "none")
{
document.all(window.event.srcElement.... + "p").style.display = "";
}
else
{document.all(window.event.srcElement... + "p").style.display = "none";
}
}
}


function clickEvent1()
{
var tag1, parenTag1;
tag1 = window.event.srcElement.tagName;
tag2 = window.event.srcElement.parentElement.ta...

if (tag1 == "H6" && tag2 == "DIV")
{
if (document.all(window.event.srcElement.id + "p").style.display == "none")
{
document.all(window.event.srcElement.id + "p").style.display = "";
}
else
{
document.all(window.event.srcElement.id + "p").style.display = "none";
}
}
}


function clickEvent2()
{
var tag1, tag2;
tag1 = window.event.srcElement.tagName;

tag2 = window.event.srcElement.id;

if (tag1 == "P" && tag2 == "PARA")
{
alert("On a trouvé tag1 = P et id = para");
if (document.all(window.event.srcElement.id + "p").style.display == "none")
{
document.all(window.event.srcElement.id + "p").style.display = "";
}
else
{
document.all(window.event.srcElement.id + "p").style.display = "none";
}
}
}
}

</script>

</head>

<body bgcolor="#8DEEEE"; onDblclick="clickEvent2()"; onKeydown="alert('Ca marche?')">

<h3 id="test" onMouseover="onMouseoverEvent()"> C'est un titre qui devrait s'ouvrir sur un texte si l'on le clique</h3>

<h3 id="testp" style="display: none"> Voila le texte dont on parle en-haut: il doit s'ouvrir, dah-dah! </h3>

<br><br><br>

<!-- div ligne pour fonction clickEvent() commence ici -->
<div style="background-color: #99CCFF">

<h6 id="ligne"; onClick="clickEvent1()"; style="font-size: 12pt; line-height: 130%">

Course description: Upon completion of the course the students are expected to understand and
address the following skills and problem areas related to their personal
leadership capacity in managerial and organizational settings:

</h6>

<h6 id="lignep"; style="display: none">

Personality Types, Career Goals, Career Life Stages and Career Development tasks</span></p>

<p>Time Management and Planning ideas and tools </p>

<p>Critical Thinking skills: effective analysis, reading, writing, presenting, and debating </p>

<p>Interpersonal Communication skills in organizations </span></p>

<p>Speech-making, Public Relations, and Interview skills</span></p>

<p>Power and Influence-making approaches</p>

<p>Conflict Management and Negotiation principles and skills </p>

<p>Leadership Styles: Typical vs. Ideal style </p>

</h6>
</div>
<!-- div lignep s'acheve ici -->

</body>
</html>

Old Pedant
06-19-2009, 03:03 AM
Ummm...are you aware that, all other things aside, that code will never work in any browser but MSIE??

ONLY MSIE uses window.event to get event information.

And only MSIE 4 required the use of document.all.

And it probably doesn't make any difference, but your semicolons in here are extraneous and technically an error:


<h6 id="ligne"; onClick="clickEvent1()"; style="font-size: 12pt; line-height: 130%">


No, I don't see offhand why you get the "Object expected" error.

Philip M
06-19-2009, 07:34 AM
parentTag1 = window.event.srcElement.parentElement.ta...
tag2 = window.event.srcElement.parentElement.ta...

Please follow the posting guidelines and wrap your code in [code] tags. This means use the octothorpe or # button on the toolbar which will insert opening [ code ] and closing [ /code ] tags - omit the spaces. You can edit your previous post, which will get rid of the smilies. Merci!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum