Image

Imagedevolve_absolve wrote in Imagejavascript 😡annoyed

Listens: Marilyn Manson - (s)AINT

*grumble grumble*

I just can't get it. I'm trying to combine a few functions which are identical in all respects into two simple (at least I thought they were) functions. My main issue is trying to use a string argument (incVar) and then use not only the string, but the variable bearing the same element (in this case incVar may be mainField, where mainField is the general category for the variables mainFieldVar and mainFieldMin



<script language="javascript">
  <!--
  var mainFieldVar=3;
  var mainFieldMin=3;
  var secFieldVar=4;
  var secFieldMin=4;
  var currentTotal=5;
  var currentMax=5;
	
	
  function addVal(incVar) {
	  if (currentTotal!=0 && currentTotal<=currentMax) {
      currentTotal--;
      mainFieldVar++;
      document.testForm[incVar].value=mainFieldVar;
      document.testForm.currentTotal.value=currentTotal;
    }
  }
	
	
  function subVal(incVar) {
	  if (currentTotal<=currentMax && mainFieldVar>mainFieldMin) {
      currentTotal++;
      mainFieldVar--;
      document.testForm[incVar].value=mainFieldVar;
      document.testForm.currentTotal.value=currentTotal;
    }
  }
	
  function addSecVal(incVar) {
	  if (currentTotal!=0 && currentTotal<=currentMax) {
      currentTotal--;
      secFieldVar++;
      document.testForm[incVar].value=secFieldVar;
      document.testForm.currentTotal.value=currentTotal;
    }
  }
	
	
  function subSecVal(incVar) {
	  if (currentTotal<=currentMax && secFieldVar>secFieldMin) {
      currentTotal++;
      secFieldVar--;
      document.testForm[incVar].value=secFieldVar;
      document.testForm.currentTotal.value=currentTotal;
    }
  }
	
  -->
  </script>





Now I have tried to use [incVar]Var and [incVar]min, but that didn't work. What I really miss is assoc $$ variables, and I was advised earlier that eval() may be the way to go, but I could not find any use for that at all. As you'll note it's effectively a counter, where each button effects a single field as well as a shared variable. All I need is for someone to please help me (no need to be overly simplistic and long, I can usually figure things out >.< ) in being able to turn incVar into Var, etc... so I can manipulate things easily.

I apologise for spamming the group recently, but I've spent hours trying to figure it out, and it's starting to really bug me =/