Solved

Function not being called

Posted on 2008-10-01
4
145 Views
Last Modified: 2010-04-21
Hi,
There is a function in this javascript file that is supposed to replace "&" with "&" and " " with a space, but it is not being called.  Any ideas?  Thanks!

Here is the page:
http://myweb.twu.edu/~bklug/catalog/js/test5.htm

I have attached my javascript.  The functions not being called are:
function ampersandReplacer() {
  var b = document.getElementsByTagName('body')[0];
  var re = /(&)/g;
 
  if( b.innerHTML.match( re ) ) {
    b.innerHTML =  b.innerHTML.replace(re,"&");
  }
}

function ampersandReplacer2() {
  var b = document.getElementsByTagName('body')[0];
  var re = /( )/g;
 
  if( b.innerHTML.match( re ) ) {
    b.innerHTML =  b.innerHTML.replace(re," ");
  }
}
//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
 
 

 
 

function numberPages() {

  var rec = window.location.href.match(/recPointer=(\d+)/);

  var counter = rec ? rec[1] : 0;

 

  var allItems = getElementsByClassName('resultListCheckBox');

  for(var i = 0, e = allItems.length; i < e; i++) {

    if(allItems[i].firstChild) {

      var span = document.createElement('span');

      span.style.paddingLeft = '20px';

      span.innerHTML = parseInt(i, 10) + parseInt(counter, 10) + parseInt(1, 10);

      allItems[i].insertBefore(span, allItems[i].firstChild);

    }

  }

}

 

//Got this from dustiandiaz.com.  No need to reinvent the wheel

function getElementsByClassName(searchClass,node,tag) {

  var classElements = new Array();

  if ( node == null ) {

          node = document;

  }

  if ( tag == null ) {

          tag = '*';

  }

  var els = node.getElementsByTagName(tag);

  var elsLen = els.length;

  var pattern = new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)');

  for (i = 0, j = 0; i < elsLen; i++) {

    if ( pattern.test(els[i].className) ) {

            classElements[j] = els[i];

            j++;

    }

  }

  return classElements;

}

 

 

function setFocus(pageName) {

   /*

   ** A pageName will get passed in , which we will use to set the focus.

   ** to add support for a new page use the /page:page/@nameId (from the XML)

   ** value for the case match, and call the focusElement() function with the

   ** id of the form element to set focus to

   ** 

   */

 

   switch(pageName)  {

    case 'page.searchBasic':

    case 'page.searchSubject':

    case 'page.searchAuthor':

       focusElement('searchArg');

       break;

       

    case 'page.searchAdvanced':

       focusElement('searchArg1');

       break;

       

    case 'page.logIn':

       focusElement('loginId');

       break;

  } 

 

  numberPages()

  ampersandReplacer();

   ampersandReplacer2();

  return true;

}

 

function ampersandReplacer() {

  var b = document.getElementsByTagName('body')[0];

  var re = /(&amp;)/g;

 

  if( b.innerHTML.match( re ) ) {

    b.innerHTML =  b.innerHTML.replace(re,"&");

  }

}
 

function ampersandReplacer2() {

  var b = document.getElementsByTagName('body')[0];

  var re = /(&nbsp;)/g;

 

  if( b.innerHTML.match( re ) ) {

    b.innerHTML =  b.innerHTML.replace(re," ");

  }

}
 
 

  <!--End edited by TWU Library  -->

 
 

 

 

//////////////////////////////////////////////////////////////////////

function focusElement(eleName) {

   if(document.getElementById(eleName)) {

      document.getElementById(eleName).focus();

   }

}

///////////////////////////////////////////////////////////////

Open in new window

0
Comment
Question by:jianxin9
  • 2
  • 2
4 Comments
 
LVL 15

Expert Comment

by:MMDeveloper
ID: 22615525
this is what I did to your code and it worked fine for me

this is inside your pageInputFocus-2.js file
function setFocus(pageName) {

   /*

   ** A pageName will get passed in , which we will use to set the focus.

   ** to add support for a new page use the /page:page/@nameId (from the XML)

   ** value for the case match, and call the focusElement() function with the

   ** id of the form element to set focus to

   **

   */
 

   switch(pageName)  {

    case 'page.searchBasic':

    case 'page.searchSubject':

    case 'page.searchAuthor':

       focusElement('searchArg');

       break;
 

    case 'page.searchAdvanced':

       focusElement('searchArg1');

       break;
 

    case 'page.logIn':

       focusElement('loginId');

       break;

  }
 

  numberPages();

  replaceChars();

  //ampersandReplacer();

   //ampersandReplacer2();

  return true;

}
 

function replaceChars() {

	b = document.getElementById("theResults");

	b.innerHTML = b.innerHTML.replace(/&amp;/g, "&");

	b.innerHTML = b.innerHTML.replace(/&nbsp;/g, " ");

}

Open in new window

0
 
LVL 15

Accepted Solution

by:
MMDeveloper earned 500 total points
ID: 22615535
ehh... ok well that last replace should have the HTML code for a space in it, when I posted it, it must have been stripped out, I'll try to post again


function setFocus(pageName) {
   /*
   ** A pageName will get passed in , which we will use to set the focus.
   ** to add support for a new page use the /page:page/@nameId (from the XML)
   ** value for the case match, and call the focusElement() function with the
   ** id of the form element to set focus to
   **
   */

   switch(pageName)  {
    case 'page.searchBasic':
    case 'page.searchSubject':
    case 'page.searchAuthor':
       focusElement('searchArg');
       break;

    case 'page.searchAdvanced':
       focusElement('searchArg1');
       break;

    case 'page.logIn':
       focusElement('loginId');
       break;
  }

  numberPages();
  replaceChars();
  //ampersandReplacer();
   //ampersandReplacer2();
  return true;
}

function replaceChars() {
      b = document.getElementById("theResults");
      b.innerHTML = b.innerHTML.replace(/&amp;/g, "&");
      b.innerHTML = b.innerHTML.replace(/&nbsp;/g, " ");
}
0
 

Author Comment

by:jianxin9
ID: 22616735
Thanks so much for posting.  When I tried it like that, it seemed to work for the "&nbsp" but not for the "&amp;", when I make this change (change on second line), it works for both, but seems to get rid of the yellow highlighting which we need.  

function replaceChars() {
       b = document.getElementsByTagName("body");
      b.innerHTML = b.innerHTML.replace(/&amp;/g, "&");
      b.innerHTML = b.innerHTML.replace(/&nbsp;/g, " ");
}

function setFocus(pageName) {

   /*

   ** A pageName will get passed in , which we will use to set the focus.

   ** to add support for a new page use the /page:page/@nameId (from the XML)

   ** value for the case match, and call the focusElement() function with the

   ** id of the form element to set focus to

   **

   */
 

   switch(pageName)  {

    case 'page.searchBasic':

    case 'page.searchSubject':

    case 'page.searchAuthor':

       focusElement('searchArg');

       break;
 

    case 'page.searchAdvanced':

       focusElement('searchArg1');

       break;
 

    case 'page.logIn':

       focusElement('loginId');

       break;

  }
 

  numberPages();

  replaceChars();

  return true;

}
 

function replaceChars() {

       b = document.getElementsByTagName("body");

      b.innerHTML = b.innerHTML.replace(/&amp;/g, "&");

      b.innerHTML = b.innerHTML.replace(/&nbsp;/g, " ");

}

Open in new window

0
 

Author Closing Comment

by:jianxin9
ID: 31501964
thanks so much!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
error email attachment VB2010 5 32
jquery validation by class 12 52
CSS Question.. 3 77
Having Returning  Anonymous Function Access Global Function 7 81
Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now