Hallo Bernhard.
<script language="JavaScript">
var wert = new Array();
wert[0] = "100";
wert[1] = "210";
wert[2] = "222";
wert[3] = "258";
var Suchbegriff = "222";
for(x=0;x<5;x++){
var Ergebnis = wert[x].search(Suchbegriff);
if(Ergebnis != -1){
alert("Der gesuchte Wert ist vorhanden");
}}
</script>Könnte es so gehen?
Nein, ganz gewiss nicht, da dein Array „wert“ lediglich vier Elemente hat, du aber ganze sechs Elemente (0 bis 5) durchläufst.
Versuche es einmal hiermit:
var wert = ['100', '210', '222', '258']; // Literalschreibweise, äquivalent zu new Array();
var Suchbegriff = '222';
for (var i = 0; i < wert.length; ++i) { // Dank lenght läuft die Schleife genau so oft durch, wie es Elemente im Array gibt
if (wert[i].search(Suchbegriff) != -1) { // Eine Zwischenspeicherung des Suchergebnisses ist nicht erforderlich
alert('Der gesuchte Wert „' + Suchbegriff + '“ ist vorhanden.');
}
}
Einen schönen Freitag noch.
Gruß, Ashura
--
sh:( fo:} ch:? rl:( br: n4:~ ie:{ mo:| va:) de:> zu:} fl:( ss:) ls:[ js:|
„It is required that HTML be a common language between all platforms. This implies no device-specific markup, or anything which requires control over fonts or colors, for example. This is in keeping with the SGML ideal.“
[HTML Design Constraints: Logical Markup]
sh:( fo:} ch:? rl:( br: n4:~ ie:{ mo:| va:) de:> zu:} fl:( ss:) ls:[ js:|
„It is required that HTML be a common language between all platforms. This implies no device-specific markup, or anything which requires control over fonts or colors, for example. This is in keeping with the SGML ideal.“
[HTML Design Constraints: Logical Markup]