The script in question:
Code:
<script type="text/javascript">
var c = document.getElementById('inqty');
var b = document.getElementById('outqty');
var a = document.getElementById('varqty');
//define c, b, a
var performSubtract = function(e) {
var key = e ? e.which : window.event.keyCode; //get the key, 13 = ENTER
if(key == 13){
a.value = c.value - b.value; //subtract and set
}
};
c.onkeydown = b.onkeydown = performSubtract;
</script>
Isn't on the page in the zip attached to your post, and neither is any element with an id of "inqty". You do have id='inqty0' through id='inqty30' though.
I'd get rid of:
Code:
<script language="javascript">
function handleEnter(e, nextfield)
{
var characterCode = (e && e.which)? e.which: e.keyCode;
if(characterCode == 13)
{
document.getElementById(nextfield).focus();
return false;
}
else
{
return true;
}
}
</script>
and the highlighted:
Code:
<body onLoad="document.clttype.clt_no.focus();">
and this (again highlighted) and all similar (there are tons of these, but probably not too many in the PHP file that created the file you sent):
Code:
<input type='text' name='ac2l' id='ac2l' onkeypress='return handleEnter(event,"b3");' />
Add this script to the head:
Code:
<script type="text/javascript">
document.onkeypress = function(e){
e = e || event; e.returnValue = true;
var t = e.target || e.srcElement, re = /^(inqty|outqty)(\d+)$/, f = arguments.callee, m, i;
function next(){
if(!f.els && (m = t.form) === document.forms.clttype){
var ipts = m.getElementsByTagName('input'), els = []; i = ipts.length - 1;
for (i; i > -1; --i){
if(ipts[i].type && ipts[i].type.toLowerCase() === 'text'){
els.push(ipts[i]);
}
}
f.els = els;
}
if(f.els){
i = f.els.length - 1;
for (i; i > -1; --i){
if(f.els[i] === t && (m = f.els[i - 1])){
m.focus();
}
}
}
}
if((m = re.exec(t.id)) && e.keyCode === 13){
e.returnValue = false;
t.form.elements['varqty' + m[2]].value = t.form.elements['inqty' + m[2]].value - t.form.elements['outqty' + m[2]].value;
} else if (t.type && e.keyCode === 13 && t.type.toLowerCase() !== 'submit') {
e.returnValue = false;
}
if(!e.returnValue){
next();
if(e.preventDefault){e.preventDefault();}
}
return e.returnValue;
}
</script>
This will supply the functionality of both the removed script and the one Nile and you were trying to get to work. It automatically determines which field is next, and (in the case of subtraction) which fields to deal with. It doesn't matter how many or how few fields there are, as long as (again, only for subtraction) there are the three fields
inqty#,
outqty#, and
varqty# for each number, 0 through however many. The body onLoad code pointed to a non-existent element, so was doing nothing other than throw an error. I'm thinking that you might want the subtraction activated differently though, other than just on hitting the ENTER key, and I wonder if subtraction is what's really required. But I leave both of those up to you to decide. Let me know if you need different or additional on that and want help implementing it.
Bookmarks