• Das Erstellen neuer Accounts wurde ausgesetzt. Bei berechtigtem Interesse bitte Kontaktaufnahme über die üblichen Wege. Beste Grüße der Admin

Inhalt einer Variable ausgeben

Cool.Runnings

New member
Hi,
ich habe folgenden JS:

Das ganze ist eine Slideshow. Ich möchte gerne das in einem Feld die Variable which (Nr des aktuellen Bildes) ausgegben wird. Wie kann ich das machen?
Außerdem wäre es nicht schlecht, dass wenn man in das Feld eine Zahl einträgt er automatisch zu dem Bild geht.


<img src="gfxu/dg0.gif" name="photoslider">
<form method="POST" name="rotater">
<script language="JavaScript1.1">
var photos=new Array()
var which=0

/*Change the below variables to reference your own images. You may have as many images in the slider as you wish*/
photos[0]="gfxu/dg0.gif"
photos[1]="gfxu/dg1.gif"
photos[2]="gfxu/dg2.gif"
photos[3]="gfxu/dg3.gif"
photos[4]="gfxu/dg4.gif"
photos[5]="gfxu/dg5.gif"
photos[6]="gfxu/dg6.gif"
photos[7]="gfxu/dg7.gif"
photos[8]="gfxu/dg8.gif"
photos[9]="gfxu/dg9.gif"

function backward(){
if (which>0){
window.status=''
which--
document.images.photoslider.src=photos[which]
}
}

function forward(){
if (which<photos.length-1){
which++
document.images.photoslider.src=photos[which]
}
else window.status='Ende der Bilder'
//which=1;backward();return false
}
</script>
<input type="button" value="<<zurück" name="B2"
onClick="backward()"> <input type="button" value="weiter>>" name="B1"
onClick="forward()"><br>
<a href="#" onClick="which=1;backward();return false">neu starten</a>
</form>
 
Ich hätte es so gemacht:

function backward()
  {
  if(which>0)
    {
    window.status=''
    which--
    document.images.photoslider.src=photos[which]
    document.rotater.counter.value=which
    }
  }

function forward()
  {
  if(which<photos.length-1)
    {
    which++
    document.images.photoslider.src=photos[which]
    document.rotater.counter.value=which
    }
  else window.status='Ende der Bilder'
  }

[...]

<input type="text" name="counter" style="border:none; width:12px;" value="0" readonly>
 
Zurück
Oben