...

View Full Version : ain't got a clue why this ain't working lol



Garadon
12-12-2002, 08:52 AM
the idea is it should take the value from a text field in one site of the form and add deduct a value from it and add the deducted value to the other side of the forms textfield.




<head>
<link rel="STYLESHEET" type="text/css" href="../styles.css">
<SCRIPT LANGUAGE="javascript">
var move=1;

function toLeft(Row)
{ var leftstr='l'+Row;
var rigthstr='r'+Row;
var rigth=eval(document.DoneForm.rigthstr.value);
var left=eval(document.DoneForm.leftstr.value);
rigth=rigth-move;
left=left+move;
if(rigth<0)
{
left=left+rigth;
rigth=0;
}
document.DoneForm.leftstr.value=left;
document.DoneForm.rigthstr.value=rigth;
}

function toRigth(Row)
{
leftstr="elements['l["+Row+"]']";
rigthstr="elements['r["+Row+"]']";
var rigth=eval(document.DoneForm.rigthstr.value);
var left=eval(document.DoneForm.leftstr.value);
rigth=rigth+move;
left=left-move;
if(left<0)
{
rigth=left+rigth;
left=0;
}
document.DoneForm.leftstr.value=left;
document.DoneForm.rigthstr.value=rigth;
}
</SCRIPT>
</head>
<body bgColor=Black Text=yellow vLink=Black Link=Black aLink=black><center>
<Table width=100% cellspacing=0 cellpadding=0 >
<FORM Name=DoneForm METHOD=POST ACTION='../piwfleet.php?fleetid=1&planetid=' target=rigth>
<tr>
<TD colspan=4>
<table cellspacing=0 cellpadding=0 border=0 width=100%>
<tr>
<td bgColor='#333333' align=center>
Destructor
</td>
<td bgColor='#777777' align=center>
Devastator
</td>
</tr>
</table>
</TD>
</tr>
<tr>
<td width=40 bgColor='#333333' align=right>
<input type=text name=l[0] value=0 size=4 readonly>
</td>
<td bgColor='#555555' align=center >
<a href='#' onClick='toLeft(0);'></a>
Destroyer
<a href='#' onClick='toRigth(0);'></a>
</td>
<td width=40 bgColor='#777777' align=left>
<input type=text name=r[0] value=200 size=4 readonly>
</td>
</tr>
<tr>
<td width=40 bgColor='#333333' align=right>
<input type=text name=l[1] value=0 size=4 readonly>
</td>
<td bgColor='#555555' align=center >
<a href='#' onClick='toLeft(1);'></a>
Gunboat
<a href='#' onClick='toRigth(1);'></a>
</td>
<td width=40 bgColor='#777777' align=left>
<input type=text name=r[1] value=100 size=4 readonly>
</td>
</tr>
<tr>
<td colspan=4 bgColor='#666666' align=center>
<INPUT class="Button1" TYPE=SUBMIT NAME=Done VALUE='Save Changes'>
</td>
</TR>
</FORM>
</Table></center>
</Body>

glenngv
12-12-2002, 09:20 AM
as much as possible, try to avoid using eval()
you can access fields by accessing the elements array indexed by the element name



function toLeft(Row)
{
var objL = document.DoneForm.elements['l['+Row+']'];
var objR = document.DoneForm.elements['r['+Row+']'];
var rigth = parseInt(objL.value,10);
var left = parseInt(objR.value,10);
rigth=rigth-move;
left=left+move;
if(rigth<0)
{
left=left+rigth;
rigth=0;
}
objL.value=left;
objR.value=rigth;
}

function toRigth(Row)
{
var objL = document.DoneForm.elements['l['+Row+']'];
var objR = document.DoneForm.elements['r['+Row+']'];
var rigth = parseInt(objL.value,10);
var left = parseInt(objR.value,10);
rigth=rigth+move;
left=left-move;
if(left<0)
{
rigth=left+rigth;
left=0;
}
objL.value=left;
objR.value=rigth;
}

Garadon
12-12-2002, 10:19 AM
have this code now, while it don't return a fault anymore it still don't do anything lol



function toLeft(Row)
{
var objL = 'document.DoneForm.elements["l['+Row+']"]';
var objR = 'document.DoneForm.elements["r['+Row+']"]';
var rigth = parseInt(objR.value,10);
var left = parseInt(objL.value,10);
rigth=rigth-move;
left=left+move;
if(rigth<0)
{
left=left+rigth;
rigth=0;
}
objL.value=left;
objR.value=rigth;
}

function toRigth(Row)
{
var objL = 'document.DoneForm.elements["l['+Row+']"]';
var objR = 'document.DoneForm.elements["r['+Row+']"]';
var rigth = parseInt(objR.value,10);
var left = parseInt(objL.value,10);
rigth=rigth+move;
left=left-move;
if(left<0)
{
rigth=left+rigth;
left=0;
}
objL.value=left;
objR.value=rigth;
}

glenngv
12-13-2002, 01:13 AM
I didn't put quotes outside the objL and objR values, did I?

var objL = 'document.DoneForm.elements["l['+Row+']"]';

objL and objL are supposed to be objects not strings!

they should be like this:

var objL = document.DoneForm.elements['l['+Row+']'];
var objR = document.DoneForm.elements['r['+Row+']'];



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum