Actualizar control mediante javascript y JSON con callback

[ permalink ] [ download ]
function json(url, querystring, destination2){

  drawSpinner(destination2);
  var jstag=document.createElement("script");
  jstag.setAttribute("type", "text/javascript");
  jstag.setAttribute("src", url+'?'+querystring);
  document.getElementsByTagName("head")[0].appendChild(jstag);
}

function jsonUpdateControl(destination1,destination2,new_options){

    hideSpinner(destination2);

    destination = gebi(destination1);

    // blank option
    //
    destination.options.length = 0;
    new_option = new Option('', '0');

    try
    {
      destination.add(new_option,null);
    } catch (e)
    {
      destination.add(new_option,-1);
    }

    // add option
    //
    var theText = '<dtml-var expr="getins('partaidea ez da agertzen zerrenda honetan')">';
    var theValue = '-1';
    new_option = new Option(theText, theValue);
    try
    {
      destination.add(new_option,null);
    } catch (e)
    {
      destination.add(new_option,-1);
    }

    // add option
    //
    var theText = ' ------------------------------------------------------------------------ ';
    var theValue = '0';
    new_option = new Option(theText, theValue);
    try
    {
      destination.add(new_option,null);
    } catch (e)
    {
      destination.add(new_option,-1);
    }

    // other options
    //  
    for(i=0;i<new_options.length;i++)
    {
      try
      {
        var theText = new_options[i]['texto'];
      } catch (e)
      {
        var theText = '--';
      }

      try
      {     
        var theValue = new_options[i]['valor'];
      } catch (e)
      {
        var theValue = '0';
      }

      if (theValue != '0')
      {
        new_option = new Option(theText, theValue);
        try
        {
          destination.add(new_option,null);
        } catch (e)
        {
          destination.add(new_option,-1);
        }
      }
    }

}
hits counter