Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ain't got a clue why this ain't working lol

    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.


    Code:
     <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>

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    as much as possible, try to avoid using eval()
    you can access fields by accessing the elements array indexed by the element name

    Code:
    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;
        }
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    have this code now, while it don't return a fault anymore it still don't do anything lol

    Code:
     
        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;
        }

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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+']'];
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •