Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't execute javascript in "BODY" section

Status
Not open for further replies.
Aug 19, 2002
10
0
0
DK
I have been trying for the last couple of days to make this script execute in the "body" of my webpage. The script looks like this in the "head" section.


<script language=&quot;JavaScript1.2&quot;>
<!--

var ns6=document.getElementById&&!document.all?1:0

var head=&quot;display:''&quot;
var folder=''

function expandit(curobj){
folder=ns6?curobj.nextSibling.nextSibling.style:document.all[curobj.sourceIndex+1].style
if (folder.display==&quot;none&quot;)
folder.display=&quot;&quot;
else
folder.display=&quot;none&quot;
}

function expanditallready(curobj){
folder=ns6?curobj.nextSibling.nextSibling.style:document.all[curobj.sourceIndex+1].style;
folder.display=&quot;&quot;;
}

//-->
</script>


This is what I have in the &quot;body&quot; section.

<cfif #Client.ExpIkkeStartet# EQ &quot;yes&quot;>
<h1 class=&quot;titleexpander&quot; style=&quot;cursor:pointer; cursor:hand&quot; onClick=&quot;expandit(this)&quot;>IKKE STARTET</h1>
<cfelseif #Client.ExpIkkeStartet# EQ &quot;no&quot;>
<h1 class=&quot;titleexpander&quot; style=&quot;cursor:pointer; cursor:hand&quot;><script type=&quot;text/javascript&quot;>expanditallready(this)</script>IKKE STARTET</h1>
</cfif>

The &quot;onClick&quot; works fine but it is the <cfelseif> clause that's giving me trouble. I want the script to execute if the <cfelseif> clause validates to true but it does not execute upon validating to true! I don't know anything about javascripting so I'm really lost here. I don't know if it's the way I'm trying to execute the script in my <cfelseif> clause or if something in the script needs to be changed in order for it to work. Any help will be greatly appreciated.


/DiXiE
 
you should be able to use this:

<cfif #Client.ExpIkkeStartet# EQ &quot;yes&quot;>
<h1 id=&quot;foo&quot; class=&quot;titleexpander&quot; style=&quot;cursor:pointer; cursor:hand&quot; onClick=&quot;expandit(this)&quot;>IKKE STARTET</h1>
<cfelseif #Client.ExpIkkeStartet# EQ &quot;no&quot;>
<script type=&quot;text/javascript&quot;>expanditallready(document.getElementById(&quot;foo&quot;))</script>
</cfif>




=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Hi Jeff,

Thank U for the quick response. Unfortunately it doesn't work. When I implement your suggestions it simply leaves out this part upon validating to true,

<cfelseif #Client.ExpIkkeStartet# EQ &quot;no&quot;>
<script type=&quot;text/javascript&quot;>expanditallready(document.getElementById(&quot;foo&quot;))</script>
</cfif>

Maybe it's the script itself?


/DiXiE
 
&quot;When I implement your suggestions it simply leaves out this part upon validating to true&quot;

did it do this before? the javascript would have no effect on CF. perhaps check with the CF forum

=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Hi Jeff,


What I meant to say was that it does not execute the javascript or maybe there is something wrong with the javascript?


/DiXiE
 
first see if your CF is working:

<cfif #Client.ExpIkkeStartet# EQ &quot;yes&quot;>
<h1 class=&quot;titleexpander&quot; style=&quot;cursor:pointer; cursor:hand&quot; onClick=&quot;expandit(this)&quot;>IKKE STARTET (YES)</h1>
<cfelseif #Client.ExpIkkeStartet# EQ &quot;no&quot;>
<h1 class=&quot;titleexpander&quot; style=&quot;cursor:pointer; cursor:hand&quot;><script type=&quot;text/javascript&quot;>expanditallready(document.getElementById(&quot;foo&quot;))</script>IKKE STARTET (NO)</h1>
</cfif>

if that's working properly, then put an alert in each function to see if it gets called:

<script language=&quot;JavaScript1.2&quot;>
<!--

var ns6=document.getElementById&&!document.all?1:0

var head=&quot;display:''&quot;
var folder=''

function expandit(curobj){
alert('expandit')
folder=ns6?curobj.nextSibling.nextSibling.style:document.all[curobj.sourceIndex+1].style
if (folder.display==&quot;none&quot;)
folder.display=&quot;&quot;
else
folder.display=&quot;none&quot;
}

function expanditallready(curobj){
alert('expanditallready')
folder=ns6?curobj.nextSibling.nextSibling.style:document.all[curobj.sourceIndex+1].style;
folder.display=&quot;&quot;;
}

//-->
</script>


if you don't get the alert, check the html source to see if CF actually wrote the function call, or check your browser for script errors.


=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top