PDA

View Full Version : Error on Page


Mel Smith
07-09-2009, 01:06 PM
Hi:

I'm just getting into js and am using the 'onclick' attribute to execute a function which I declared in the <head>.

This worked great, so now I have made it more complex and I now have an error message:

'Error on Page' message on the bottom left of the window, then, the 'done' message comes up on my IE 7, and the expected action withing my function does not occur. I can't even get an Alert() message to show -- just the error message.

On Firefox and Safari there is no error message, but no action takes palce either.

So, I tried to debug it manually, but can't seem to find the error.

Question: Is there a debugger I can use for IE7 or firefox or Safari, or can I post this beginner-type code here and hope that someone can spot the error ?


Thanks for your understanding !

-Mel Smith

coothead
07-09-2009, 03:05 PM
Hi there Mel Smith,

post the page code, we may possibly be able to spot the error for you. ;)

Mel Smith
07-09-2009, 04:23 PM
Hi Coothead:

After working all day on it, I *finally* found the error (aside from missing semi-colons, curly brackets, etc, etc.):

The major error was using ':=' as an assignment operator instead of '=' :((

I spend half my time building proggies using ':=', and I got caught in js with this error.

My page is mostly a set of 24 checkboxes (arranged in 3 columns of 8 boxes) which I have to manipulate so that the user can only 'check' 8 of the 24 boxes., and as he does so, I display a value in eight readonly input text boxes across the bottom of the page. When he 'submits', I place these choices in a database so that later he may edit them and change his priorities.


Please don't laugh too loud at the code below :))


-Mel Smith

*************** my embedded js in the <head> of my page *******

<script type="text/javascript">
var b = '';
var a = [b,b,b,b,b,b,b,b];
var lastslot = -1;

function init() {

var asrvc;
var asrvcs = document.getElementsByName('srvcs');
var asrvclen = asrvcs.length;
var fldname,j,e;

for (var i = 0; i < asrvclen ; i++) {
asrvc = asrvcs[i];
if (asrvc.checked) {
lastslot++;
a[lastslot] = asrvc.value;
j = lastslot + 1 ;
fldname = 'fsrvc'+j ;
e = document.getElementById(fldname);
e.style.fontweight="bold";
e.style.color="red";
e.style.background="white";
e.value = a[lastslot].toUpperCase();
};
};
}

function aScan(srchary,srchval) {
var nLen = srchary.length;

for(var i = 0 ; i < nLen; i++) {
if (srchary[i] == srchval) return i;
};

return 9999;
}

function setcode(srvccode,enabled) {
// This function will set a code in the bottom
// box when a checkbox is clicked

if (enabled) {
if (lastslot >= 7) {
alert("Only 8 Priority Services Allowed !");
return false;
};
var i = aScan(a,b);
}
else {
var i= aScan(a,srvccode);
};

if (i==9999) {return false;};

var j = i + 1;

if (j > 8) {
// can only have 8 priority fields
alert("Only 8 Priority services allowed !");
return ;
};

if (enabled) {
// now use 'j' to produce the appropriate priority field name
var fldname = 'fsrvc'+j ;
var e = document.getElementById(fldname);
e.style.fontweight="bold";
e.style.color="red";
e.style.background="white";
a[i] = srvccode;
lastslot = i ;
e.value = a[i].toUpperCase() ;
}
else {
// we know that 'lastslot' points to
// the position of the last filled slot
if (i < lastslot) {
// have to eliminate the field and put blank at end ??
a.splice(i,1);
a.splice(lastslot,0,b);
}
else {
a[i] = b;
};

lastslot -= 1 ;
// now rebuild/repaint the priority fields
var e,fldname;
for(var k = 0; k <= 7; k++) {
fldname = 'fsrvc'+(k+1) ;
if (a[k] == b) {
e = document.getElementById(fldname);
e.style.fontweight="normal";
e.style.color="black";
e.style.background="wheat";
e.value = a[k] ;
}
else {
e = document.getElementById(fldname);
e.style.fontweight="bold";
e.style.color="red";
e.style.background="white";
e.value = a[k].toUpperCase();
};
};
};
}

</script>