Forum Moderators: open

Message Too Old, No Replies

How to Call a Function from the DIV tag of HTML

         

Roudra

11:56 am on Nov 25, 2008 (gmt 0)

10+ Year Member



Hi, i am trying to call a javascript function from within a div tag on click of it. while calling the function i intend to pass the id of the div as an object to the called function. I have the below code in HTML.Using this code, when i click on the DIV in the HTML, the javascript function is not getting called. Please advise...

<body>
<div id="Header" style="display:block; float:left; width:100%; clear:both;" >
<img src="ToolImages/Oracle.gif" alt="Oracle Logo" style="float:left" >

</div>

<div class="tabber" id="tab1">

<div class="tabbertab">
<h2><a name="tab1">Templates</a></h2>
<div class="tabber" id="tab1-1">

<div class="tabbertab">
<h3>Landing Page</h3>

<textarea class="HTMLArea" name="EditLandingPage" >
<link href="Theme/Flexblue.css" rel="stylesheet" type="text/css">
<link href="Theme/en.css" rel="stylesheet" type="text/css">
<br>
<body class="BODYLanding">

<table title="Menu Bar" class="TABLELogoBar" id="TABLELogoBar" width="100%" border="0" cellspacing="0" cellpadding="0" style="border:1px dotted red">
<tr>
<td>&nbsp;</td>
</tr>
</table>

<table title="Tool Bar" id="TABLEToolBar" style="height:32px;border:1px dotted red" width="100%" border="0" cellspacing="0" cellpadding="0" summary="Tool Bar">
<tr>
<td>&nbsp;</td>
</tr>
</table>

<div id="DIVNavPane" onclick="getId(this.id)" class="DIVNavPane" style="height:600px;border:1px dotted red" title="Left Pane" >

</div>

<div id="DIVTaskArea" onclick="getId(this.id)" class="DIVTaskArea" style="height:600px;border:1px dotted red" title="Task Area" >

</div>

</body>

</textarea><br>

penders

2:46 pm on Nov 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It looks like you are trying to contain one HTML document (the one with your DIV/onclick tags) inside a TEXTAREA element of another document!? This is not valid HTML.

Roudra

4:51 am on Nov 26, 2008 (gmt 0)

10+ Year Member



Yes my HTML doc is actually contained inside the text area of another html doc. The js function i m calling is as below:

function getId(id) {
var a = document.getElementById(id);
alert(a.id);
}

Please tell me how to go ahead...

penders

8:18 am on Nov 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I thought I was seeing double... same thread in JS forum:
[webmasterworld.com...]

Roudra

8:37 am on Nov 26, 2008 (gmt 0)

10+ Year Member



Yes i know.. But can you suggest me a way out...

<div id="DIVNavPane" class="DIVNavPane" style="height:600px;border:1px dotted red" title="Left Pane" >
<script language="javascript1.2">
document.getElementById('DIVNavPane').onclick = function() {
alert('DIVNavPane');
fnGetId(this.id);

}
</script>

</div>

This is what i have written now.. but the problem is that i am able to get the alert msg. but for teh function call.... i get an Object Expected error. The function called is:

function getId(id) {

alert('DIV');
}

[edited by: Roudra at 8:39 am (utc) on Nov. 26, 2008]

tedster

8:57 am on Nov 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There are two threads discussing this same issue, and that gets confusing for anyone trying to follow the complete discussion - whether now or in the future. Let's take the rest of this conversation over to the thread in the Javascript Forum.

[webmasterworld.com...]