Dirk: Sinnvolles Zitieren

Beitrag lesen

willst du uns veräppeln?
Oder warum sagst du sinngemäß, "sorry, is' klar", und klatscht trotzdem wieder das *komplette* Vorposting hier rein?

Mein Gott! Das waren in diesem Falle nur zwei Zeilen mehr, als wenn ich den restlichen Kladderadatsch rausgenommen hätte!

Hier meine Lösung für die Allgemeinheit. Vielleicht nicht JavaScript-Guru-Supercode, aber es funktioniert:

function updateCheckItemStatusCounter(openStateCounterFieldId,
           conditionStateCounterFieldId,
           hiddenField, selector)
{
 var oldIdx = 0;
 if ( document.getElementById(hiddenField).value == null || document.getElementById(hiddenField).value == '' )
 {
  for (var i=0; i<selector.options.length; i++)
  {
   if ( selector.options[i].defaultSelected == true )
   {
    oldIx = i;
   }
  }//end for i
 } else
 {
  oldIdx = document.getElementById(hiddenField).value;
 }

var idx = parseInt(selector.selectedIndex);
 var openNode = document.getElementById(openStateCounterFieldId);
 var conditionNode = document.getElementById(conditionStateCounterFieldId);
 var openCounter = parseInt(openNode.firstChild.nodeValue);
 var conditionCounter = parseInt(conditionNode.firstChild.nodeValue);

switch (parseInt(oldIdx))
 {
  case 0: if ( openCounter > 0 )
    {
     openCounter--;
    }
    break;
  case 1: if ( openCounter > 0 )
    {
     openCounter--;
    }
    if ( conditionCounter > 0 )
    {
     conditionCounter--;
    }
    break;
  case 2: if ( openCounter > 0 )
    {
     openCounter--;
    }
    if ( conditionCounter > 0 )
    {
     conditionCounter--;
    }
    break;
  case 3: if ( conditionCounter > 0 )
    {
     conditionCounter--;
    }
    break;
 }

switch (idx)
 {
  case 0: openCounter++;
    break;
  case 1: break;
  case 2: break;
  case 3: conditionCounter++;
    break;
 }

openNode.firstChild.nodeValue = openCounter;
 conditionNode.firstChild.nodeValue = conditionCounter;
 document.getElementById(hiddenField).value = idx;
}//end updateCheckItemStatusCounter