jianxin9
asked on
Function not being called
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.getElementsByTagN ame('body' )[0];
var re = /(&)/g;
if( b.innerHTML.match( re ) ) {
b.innerHTML = b.innerHTML.replace(re,"&" );
}
}
function ampersandReplacer2() {
var b = document.getElementsByTagN ame('body' )[0];
var re = /( )/g;
if( b.innerHTML.match( re ) ) {
b.innerHTML = b.innerHTML.replace(re," ");
}
}
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.getElementsByTagN
var re = /(&)/g;
if( b.innerHTML.match( re ) ) {
b.innerHTML = b.innerHTML.replace(re,"&"
}
}
function ampersandReplacer2() {
var b = document.getElementsByTagN
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 = /(&)/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," ");
}
}
<!--End edited by TWU Library -->
//////////////////////////////////////////////////////////////////////
function focusElement(eleName) {
if(document.getElementById(eleName)) {
document.getElementById(eleName).focus();
}
}
///////////////////////////////////////////////////////////////
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks so much for posting. When I tried it like that, it seemed to work for the " " but not for the "&", 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.getElementsByTagN ame("body" );
b.innerHTML = b.innerHTML.replace(/& /g, "&");
b.innerHTML = b.innerHTML.replace(/  ;/g, " ");
}
function replaceChars() {
b = document.getElementsByTagN
b.innerHTML = b.innerHTML.replace(/&
b.innerHTML = b.innerHTML.replace(/ 
}
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(/&/g, "&");
b.innerHTML = b.innerHTML.replace(/ /g, " ");
}
ASKER
thanks so much!
this is inside your pageInputFocus-2.js file
Open in new window