Fußball Aufstellungscript, Fragen...

DonDemf

Erfahrenes Mitglied
Hallo Leuts,
ich werde in diesem Thema immer mal wieder ein paar Fragen zu einem php Script stellen, welches ich teilweise mit Javascript verwirkliche. Ich habe bereits hilfe von einem netten Java-Script Programmierer aus diesem Forum erhalten und hoffe das andere mir ebenfalls helfen würden ;-)

Also ich benutze folgenden Javascript:
Code:
<script language="javascript" type="text/javascript">
function formation(form) {
if (form == 1) {
    pos_x = new Array(33, 145, 274, 392, 215, 378, 50, 215, 313, 116);
    pos_y = new Array(501, 501, 501, 501, 409, 325, 325, 251, 153, 153);
} else if (form == 2) {
    pos_x = new Array(150);
    pos_y = new Array(200);
} else if (form == 3) {
    pos_x = new Array(200);
    pos_y = new Array(200);
}

for ($a = 1; $a < 5; $a++) {
    document.getElementById("s" + $a).style.left = pos_x[$a-1];
    document.getElementById("s" + $a).style.top = pos_y[$a-1];
}

}
</script>

Momentan habe ich nur die Koordianten für die 4-1-2-1-2 Formationen reingeschrieben, was sich aber bald ändert.
Meine aktuelle frage lautet jedoch, wie verwirkliche ich es, dass die 4-1-2-1-2 Koordinaten die standart Koordianten des Script sind, wenn man die seite aufruft?

http://fifaplace.pytalhost.com/fifaliga/spielfeld/spielfeld.html

Vielen Dank schonmal für die Hilfe. :-)
 
Ruf einfach formation(1) beim Laden auf.

Aber ich würde das ganze etwas anders Lösen. Entweder mit einem zweidimensionalen Array oder einem Objekt. Dieses if-else Konstrukt ist doch nervig. Nimm dann als "value" Attribut auch nicht mehr 1, 2, 3 etc. (versteht kein Mensch), sondern "4-1-2-1-2" etc.

Javascript:
<script language="javascript" type="text/javascript">
var all = {
    "4-1-2-1-2": {
        x: [33, 145, 274, 392, 215, 378, 50, 215, 313, 116],
        y: [501, 501, 501, 501, 409, 325, 325, 251, 153, 153]
    },
    "4-4-2": {
        x: [0,1,2,3,4,5,6,7,8,9],
        y: [9,8,7,6,5,4,3,2,1,0]
    }
    //usw.
};

function formation(form) {
    var pos = all[form];

    for (var $a = 1; $a < 5; $a++) {
        document.getElementById("s" + $a).style.left = pos.x[$a-1];
        document.getElementById("s" + $a).style.top = pos.y[$a-1];
    }
}

window.onload = function() {
    formation("4-1-2-1-2")//Default
};
</script>
 
Habe es nun so gemacht wie du es meintest, jedoch funktioniert nun gar nichts mehr :S

Code:
<script language="javascript" type="text/javascript">
var all = {
    "4-1-2-1-2": {
        x: [33, 145, 274, 392, 215, 378, 50, 215, 313, 116],
        y: [501, 501, 501, 501, 409, 325, 325, 251, 153, 153]
    },
    "4-3-3": {
        x: [501, 501, 501, 501, 409, 325, 325, 251, 153, 153],
        y: [501, 501, 501, 501, 327, 301, 301, 125, 144, 144]
    },
	"4-3-1-2": {
        x: [33, 145, 274, 392, 212, 365, 54, 212, 329, 94],
        y: [501, 501, 501, 501, 348, 315, 315, 226, 125, 125]
    },
	"4-3-2-1": {
        x: [33, 145, 274, 392, 212, 365, 54, 212, 344, 79],
        y: [501, 501, 501, 501, 348, 315, 315, 128, 171, 171]
    }
    //usw.
};
function formation(form) {
    var pos = all[form];
 
    for (var $a = 1; $a < 5; $a++) {
        document.getElementById("s" + $a).style.left = pos.x[$a-1];
        document.getElementById("s" + $a).style.top = pos.y[$a-1];
    }
}
 
window.onload = function() {
    formation("4-1-2-1-2")//Default
};
</script>

Und
Code:
Spielerformation : <select name="formation" size="1" onchange="formation(this.value);">
    <option value="1" selected="selected">4-1-2-1-2</option>
    <option value="2" >4-3-3</option>
    <option value="3">4-3-1-2</option>
    <option value="4">4-3-2-1</option>
    <option value="5">4-2-2-2</option>
    <option value="6">4-4-2</option>
    <option value="7">4-2-3-1</option>
    <option value="8">4-5-1</option>
    <option value="9">5-2-2-1</option>
    <option value="10">5-2-1-2</option>
    <option value="11">3-4-1-2</option>
    <option value="12">3-4-2-1</option>
    <option value="13">3-4-3</option>
</select>


Er hat nun weder die Standartformation, noch wechselt er sie.
 
richtig, sorry ;-)


Nun aber mal ne andere frage und zwar möchte ich aus meiner mysql datenbank die standart Formation auslesen lassen von jedem User. Dazu müsste ich ja im Javascript bei
Code:
window.onload = function() {
    formation("4-1-2-1-2")//Default
};

php anwenden. Ist das möglich im Javascript php anzuwenden?
 
Ob das JavaScript ist oder nicht, spielt ja keine Rolle. Du kannst überall php einfügen

HTML:
<?php
    //Datenbankabfrage...
    $val = '4-1-2-1-2';
?>

<script type="text/javascript">
window.onload = function() {
    formation("<?php echo $val; ?>")//Default
};
</script>
 
Ein großer Kasten mit style="position:relative;", in den alle deine selects kommen.

Deine absoluten Positionsangaben beziehen sich immer auf das nächste Eltern Element mit absoluter oder relativer Positionierung. Im Moment das Dokument selbst. Deshalb ein div drumherum, damit sich die angaben auf das div beziehen.
 

Neue Beiträge

Zurück