[js] een variabele variabelenaam maken

Pagina: 1
Acties:

  • tombo_inc
  • Registratie: December 2004
  • Laatst online: 10-03 13:21
beste mensen,

ik ben bezig met een script die de content van een tabel automatisch erin laad afhankelijk van welk item is geselecteerd in een select form. nu heb ik alle content in een content.js file zitten en het script in scripts.js. de contentfile ziet er zo uit:
code:
1
2
prefix_naam = 'hier de content';
enz..

mijn script ziet er zo uit:
code:
1
2
3
4
5
function docontent() {
var obj = document.getElementById('formulier').selectbox;
var waarde = obj.options[obj.selectedIndex].value;
document.getElementById('tablecontent').innerHTML = ??;
}

en op de plaats van de vraagtekens moet dan de samengestelde varnaam komen. maar ik zou niet weten hoe ik dat moet doen.
ik wil dus dat op de vraagtekens prefix_waarde komt, maar hier moet waarde dus worden vervangen door de value van waarde. zodat er een varnaam onstaat die gelijk is aan een varnaam uit content.js. op die manier moet dus de innerHTML een waarde uit content.js krijgen.

kan iemand mij mssn helpen?

Microsoft Windows: A thirty-two bit extension and graphical shell to a sixteen-bit patch to an eight-bit operating system originally coded for a four-bit microprocessor which was written by a two-bit company that can't stand one bit of competition


Verwijderd

zoek eens op associated arrays, denk dat dat eigenlijk het handigste is.

je zou het ook met window['var_naam'] kunnen doen voor glabals, maar da's redelijk smerig imho

  • tombo_inc
  • Registratie: December 2004
  • Laatst online: 10-03 13:21
wat moet ik dan met window doen? dit heeft toch niks met windows te maken?
mssn snap ik het verkeerd?

[ Voor 23% gewijzigd door tombo_inc op 04-01-2005 22:45 ]

Microsoft Windows: A thirty-two bit extension and graphical shell to a sixteen-bit patch to an eight-bit operating system originally coded for a four-bit microprocessor which was written by a two-bit company that can't stand one bit of competition


  • André
  • Registratie: Maart 2002
  • Laatst online: 16:30

André

Analytics dude

Tombo_inc schreef op dinsdag 04 januari 2005 @ 22:39:
wat moet ik in gods naam met window doen? dit heeft toch niks met windows te maken?
Alle objecten, variabelen, enz zijn onderdeel van het allesomvattende window object.

  • tombo_inc
  • Registratie: December 2004
  • Laatst online: 10-03 13:21
ja dat weet ik maar window['blaat'] daar kan ik toch niks mee? en in mijn probleem heb ik toch ook niks met windows te maken. het gaat hier om variabelen. maar het kan zijn dat ik iets over het hoofd zie |:(

Microsoft Windows: A thirty-two bit extension and graphical shell to a sixteen-bit patch to an eight-bit operating system originally coded for a four-bit microprocessor which was written by a two-bit company that can't stand one bit of competition


Verwijderd

ja dus, heb je er al mee gestoeid? dan wordt het je vanzelf duidelijk
JavaScript:
1
2
3
4
5
6
7
var mophor = 'cool';

alert(window['mophor']);

//of zelfs:

window['alert'](window['mophor']);

[ Voor 23% gewijzigd door Verwijderd op 04-01-2005 22:53 ]


  • tombo_inc
  • Registratie: December 2004
  • Laatst online: 10-03 13:21
ja ok, dat van die window wordt me wel al een beetje duidelijk. maar daarmee los ik denk ik mijn probleem niet op. ik denk dat ik toch de weg van de associated array op moet.

Microsoft Windows: A thirty-two bit extension and graphical shell to a sixteen-bit patch to an eight-bit operating system originally coded for a four-bit microprocessor which was written by a two-bit company that can't stand one bit of competition


Verwijderd

da's dus eigenlijk hetzelfde, alleen dan binnen een array, da's ook wel zo netjes

  • tombo_inc
  • Registratie: December 2004
  • Laatst online: 10-03 13:21
ja nu werkt het. met window[] en zonder ook maar dan met een acc array. bedankt allemaal ;)

Microsoft Windows: A thirty-two bit extension and graphical shell to a sixteen-bit patch to an eight-bit operating system originally coded for a four-bit microprocessor which was written by a two-bit company that can't stand one bit of competition

Pagina: 1