<?
class frmJavascript extends MForm
{

	function __construct()
    {   
		parent::__construct('Using Javascript');
		if($this->page->isPostBack())
		{
			$this->eventHandler();
		}
        $this->addField(new MSeparator()); 
        $this->addField(new ViewSource(__FILE__));
	}

	function createFields()
	{
        for($i=0; $i < 10; $i++)
        {
            $c = new MTextField("edtMoney$i",'0','Valor');
            $c->addEvent('blur',"RefreshSoma($i);");
            $control[] = $c; 
        }
        $this->addField(new MText("txt",'Soma atualizada a cada valor digitado'));
        $this->addField(new MSeparator()); 
        $this->addField(new MIndexedControl('ixcontrol', 'Label', $control));
        $this->addField(new MTextField("edtSoma",'0','Soma'));
        $this->txt->setBold();
        $buttons = array(
			new MButton('btnPost','Enviar')
		);
		$this->setButtons($buttons);
        $pageName = $this->page->name;
        $code = 
<<< HERE

function RefreshSoma(i) {
   auxObject = miolo.getElementById("ixcontrol_"+i); 	
   somaObject = miolo.getElementById("edtSoma"); 	
   if (isNaN(Number(auxObject.value)))
   {
      alert('NÃ£o Ã© um valor vÃ¡lido!');
      auxObject.focus();
   }
   else
   {   	
      somaObject.value = Number(somaObject.value) + Number(auxObject.value);
   }
}

HERE;

        $this->page->addJsCode($code); 
	}

}
?>