×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Javascript in Content Editor Web Part

Javascript in Content Editor Web Part

Javascript in Content Editor Web Part

(OP)
Hi,

I created a page using enterpise wiki template. I added a Content Editor Web Part to the page and entered a link to an html page that has javascript in it. The javascript is supposed to expand and collapse items associated with a few buttons. The scrip works in an html page correctly. When I open the page in the content editor web part I am only able to click on the buttons. As soon as I click on a button it does what it is supposed to do but right after that it expands all options. If I want to collapse something it wont stay collapsed for more than a second. Below is what the html & javascript looks like. Is there something I am missing? Thanks for you help.

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type>
<STYLE type=text/css>.style4 {
 TEXT-ALIGN: left
}
</STYLE>
 
<SCRIPT type=text/javascript>
 
 var objGroup;
 var btnGroup;
 var btnObject;
 var sumStatus = "false";
 
 function toggleRows(id) {
     objGroup = document.getElementsByTagName("tr");
     btnObject = document.getElementById("btn_" + id);
     btnObject.value = (btnObject.value == '+') ? '-' : '+';
     for (var i = 0; i < objGroup.length; i++) {
         try {
             if (objGroup[i].attributes["id"].value == id) {
                 objGroup[i].style.display = (objGroup[i].style.display == 'none') ? ' : 'none';
             } else if (objGroup[i].attributes["parent"].value == id && objGroup[i].style.display == ') {
                 objGroup[i].style.display = 'none';
                 document.getElementById("btn_" + objGroup[i].attributes["id"].value).value = "+";
             }
         } catch (e) {}
     }
 }

 
 function init_page() {
 
     objGroup = document.getElementsByTagName("tr");
     btnGroup = document.getElementsByTagName("button");
 
 for (var i = 0; i < objGroup.length; i++) {
             try {
               
                 if (objGroup[i].attributes["id"].value != "parent") {
                     objGroup[i].style.display = "none";
                 }
             } catch (e) {}
         }
         
         for (var i = 0; i < btnGroup.length; i++) {
             try {
               
                     btnGroup[i].value = "+";
             } catch (e) {}
         }
 
 
 
 }
 
 function togglewhole() {
     objGroup = document.getElementsByTagName("tr");
     btnGroup = document.getElementsByTagName("button");
     ourBtn = document.getElementById("btn_whole");
     var text = ourBtn.value;
     var bool = "";
     if (text == "+") {
         sumStatus = "true";
         ourBtn.value = "-";
         for (var i = 0; i < objGroup.length; i++) {
             try {
               
                 if (objGroup[i].attributes["id"].value != "parent") {
                     objGroup[i].style.display = "";
                 }
             } catch (e) {}
         }
         
         for (var i = 0; i < btnGroup.length; i++) {
             try {
               
                     btnGroup[i].value = "-";
             } catch (e) {}
         }
 
     } else {
         sumStatus = "false";
         ourBtn.value = "+";
         for (var i = 0; i < objGroup.length; i++) {
             try {
                 if (objGroup[i].attributes["id"].value != "parent") {
                     objGroup[i].style.display = "none";
                 }
             } catch (e) {}
         }
         for (var i = 0; i < btnGroup.length; i++) {
             try {
               
                     btnGroup[i].value = "+";
             } catch (e) {}
         }
     }
 }
</SCRIPT>
<META name=GENERATOR content="MSHTML 8.00.7600.16821"></HEAD>
<BODY onload="init_page()">
<TABLE style="WIDTH: 100%" cellSpacing=0>
  <TBODY class=style4>
  <TR style="DISPLAY: inline" id=parent name="parent">
    <TD style="WIDTH: 29px"><BUTTON id=btn_whole
      onclick="togglewhole(')">-</BUTTON></TD>
    <TD style="DISPLAY: inline" class=style4>Show/Hide all Features</TD></TR>
  <TR style="DISPLAY: inline" id=parent name="parent">
    <TD style="WIDTH: 29px"><BUTTON id=btn_id
      onclick="toggleRows('id')">-</BUTTON></TD>
    <TD style="DISPLAY: inline" class=style4>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Group1</TD></TR>
  <TR style="DISPLAY: inline" id=id name="id">
    <TD style="WIDTH: 29px"></TD>
    <TD style="DISPLAY: inline"
      class=style4>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      Group1 - Item1</TD></TR>
  <TR style="DISPLAY: inline" id=id name="id">
    <TD style="WIDTH: 29px"></TD>
    <TD style="DISPLAY: inline"
      class=style4>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Group1 - Item2</TD></TR>
  <TR style="DISPLAY: inline" id=parent name="parent">
    <TD style="WIDTH: 29px"><BUTTON id=btn_id1
      onclick="toggleRows('id1')">-</BUTTON></TD>
    <TD style="DISPLAY: inline" class=style4>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Group2</TD></TR>
  <TR style="DISPLAY: inline" id=id1 name="id1">
    <TD style="WIDTH: 29px"></TD>
    <TD style="DISPLAY: inline"
      class=style4>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      Group2 - Item1</TD></TR>
  <TR style="DISPLAY: inline" id=id1 name="id1">
    <TD style="WIDTH: 29px"></TD>
    <TD style="DISPLAY: inline"
      class=style4>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      Group2 - Item2</TD></TR>
  <TR style="DISPLAY: inline" id=id1 name="id1">
    <TD style="WIDTH: 29px"></TD>
    <TD style="DISPLAY: inline"
      class=style4>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Group2 - Item3</TD></TR>
  <TR style="DISPLAY: inline" id=parent name="parent">
    <TD style="WIDTH: 29px"><BUTTON id=btn_id2
      onclick="toggleRows('id2')">-</BUTTON></TD>
    <TD style="DISPLAY: inline" class=style4>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Group3</TD></TR>
  <TR style="DISPLAY: inline" id=id2 name="id2">
    <TD style="WIDTH: 29px"></TD>
    <TD style="DISPLAY: inline" class=style4>&nbsp;</TD></TR></TBODY></TABLE></BODY></HTML>

RE: Javascript in Content Editor Web Part

(OP)
I am using SharePoint 2010 for this purpose.

Thanks.

RE: Javascript in Content Editor Web Part

Have you tried using the HTML Form Web Part?


I was having this same issue last week.

Also had to use / reference jquery files I added to the site.

http://www.sharepointed.com/

RE: Javascript in Content Editor Web Part

(OP)
I get the same result with an HTML form web part.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close