Der Code soll das Formular auf Seite A ausfüllen und dann auch die nächste Seite B über einen Klick auf den Submit Button und dem anschiesenden Füllen , füllen.
Das Problem ist dass es sobald es die Seite wechselt den rest nicht mehr durchführt
var iKnopf = document.createElement("button");
var Text = document.createTextNode("Macro ausführen");
iKnopf.appendChild(Text);
iKnopf.onclick = function() {
alert("Hallo");
document.testformular.Vorname.value = "Tom";
document.testformular.Zuname.value = "Müller";
document.testformular.Wohnort.value = "München";
document.testformular.auswahl[0].checked=true;
document.testformular.Zahlmethode.value = "Visa";
document.getElementById("submit").click();
document.testformular2.auswahl[2].checked=true;
document.testformular2.Zahlmethode.value = "AmericanExpress";
}
document.getElementById("Formular").appendChild(iK nopf);
Testseite:
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Testseite</title>
</head>
<body>
<div id="Formular">
<form action="testseite2.html" name="testformular">
<fieldset>
Vorname: <input type="text" name="Vorname" maxlength="30"><br>
Nachname: <input type="text" name="Zuname" maxlength="40"><br>
Wohnort: <input type="text" name="Wohnort" maxlength="40"><br>
</fieldset>
<fieldset>
Option A:<input type="checkbox" name="auswahl" value="Option A"><br>
Option B:<input type="checkbox" name="auswahl" value="Option B"><br>
Option C:<input type="checkbox" name="auswahl" value="Option C"><br>
</fieldset>
<fieldset>
Mastercard:<input type="radio" id="mc" name="Zahlmethode" value="Mastercard"><br>
Visa:<input type="radio" id="vi" name="Zahlmethode" value="Visa"><br>
AmericanExpress:<input type="radio" id="ae" name="Zahlmethode" value="AmericanExpress"><br>
</fieldset>
<button id="submit" type="submit">senden</button>
</form>
</div>
</body>
</html>
Testseite2:
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Testseite</title>
</head>
<body>
<div id="Formular">
<form action="testseite1.html" name="testformular2">
<fieldset>
Option A:<input type="checkbox" name="auswahl" value="Option A"><br>
Option B:<input type="checkbox" name="auswahl" value="Option B"><br>
Option C:<input type="checkbox" name="auswahl" value="Option C"><br>
</fieldset>
<fieldset>
Mastercard:<input type="radio" id="mc" name="Zahlmethode" value="Mastercard"><br>
Visa:<input type="radio" id="vi" name="Zahlmethode" value="Visa"><br>
AmericanExpress:<input type="radio" id="ae" name="Zahlmethode" value="AmericanExpress"><br>
</fieldset>
<button id="submit" type="submit">senden</button>
</form>
</div>
</body>
</html>
Das Problem ist dass es sobald es die Seite wechselt den rest nicht mehr durchführt
var iKnopf = document.createElement("button");
var Text = document.createTextNode("Macro ausführen");
iKnopf.appendChild(Text);
iKnopf.onclick = function() {
alert("Hallo");
document.testformular.Vorname.value = "Tom";
document.testformular.Zuname.value = "Müller";
document.testformular.Wohnort.value = "München";
document.testformular.auswahl[0].checked=true;
document.testformular.Zahlmethode.value = "Visa";
document.getElementById("submit").click();
document.testformular2.auswahl[2].checked=true;
document.testformular2.Zahlmethode.value = "AmericanExpress";
}
document.getElementById("Formular").appendChild(iK nopf);
Testseite:
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Testseite</title>
</head>
<body>
<div id="Formular">
<form action="testseite2.html" name="testformular">
<fieldset>
Vorname: <input type="text" name="Vorname" maxlength="30"><br>
Nachname: <input type="text" name="Zuname" maxlength="40"><br>
Wohnort: <input type="text" name="Wohnort" maxlength="40"><br>
</fieldset>
<fieldset>
Option A:<input type="checkbox" name="auswahl" value="Option A"><br>
Option B:<input type="checkbox" name="auswahl" value="Option B"><br>
Option C:<input type="checkbox" name="auswahl" value="Option C"><br>
</fieldset>
<fieldset>
Mastercard:<input type="radio" id="mc" name="Zahlmethode" value="Mastercard"><br>
Visa:<input type="radio" id="vi" name="Zahlmethode" value="Visa"><br>
AmericanExpress:<input type="radio" id="ae" name="Zahlmethode" value="AmericanExpress"><br>
</fieldset>
<button id="submit" type="submit">senden</button>
</form>
</div>
</body>
</html>
Testseite2:
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Testseite</title>
</head>
<body>
<div id="Formular">
<form action="testseite1.html" name="testformular2">
<fieldset>
Option A:<input type="checkbox" name="auswahl" value="Option A"><br>
Option B:<input type="checkbox" name="auswahl" value="Option B"><br>
Option C:<input type="checkbox" name="auswahl" value="Option C"><br>
</fieldset>
<fieldset>
Mastercard:<input type="radio" id="mc" name="Zahlmethode" value="Mastercard"><br>
Visa:<input type="radio" id="vi" name="Zahlmethode" value="Visa"><br>
AmericanExpress:<input type="radio" id="ae" name="Zahlmethode" value="AmericanExpress"><br>
</fieldset>
<button id="submit" type="submit">senden</button>
</form>
</div>
</body>
</html>
Comment