Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

JavaScript Problem

Empfohlene Antworten

Veröffentlicht

Hallo zusammen,

ich habe da ein interessantes Problem. Ich habe ein Formular mit zwei Optionsfelder und zwei Inputboxen. Je nachdem, welches Optionsfeld angewählt ist, soll das Formular an eine andere Seite geschickt werden.

Ich habe bisher folgenden Ansatz.


<script language="JavaScript">
function pruefen ()
{
if (document.Auswertung.Auswahl[0].checked == true)
{
alert ("Jahresauswertung");
window.location.href="jahr.php3";
}
else
{
alert ("Monatsauswertung");
window.location.href="monat.php3";
}
}
</script>

<form name="Auswertung">
<p>Geben Sie Ihre Zahlungsweise an:</p>
<p>
<input type="radio" name="Auswahl" value="Jahr"> Jahresauswertung<br>
<input type="radio" name="Auswahl" value="Monat" checked> Monatsauswertung<br>
<input type="text" name="Jahre">
<input type="text" name="Monate">
</p>
<input type="button" value=" Absenden" onclick='pruefen ()'>

</form>[/CODE]

Mit window.location.href ruft der Browser zwar die richtige Seite auf, aber das Formular wird nicht gesendet. Ich muss auf der Seite monat.php3 bzw. jahr.php3 die beiden Inputfelder zur Verarbeitung haben. Wie stelle ich das jetzt an?

Frank

Nabend,

ich weiß zwar nicht, wie Du das mit JavaScript lösen kannst, aber wenn Du eh mit PHP arbeitest, wieso packst Du dann nicht die monat.php und die jahr.php in eine Datei und überprüfst dort, welcher Radiobutton ausgewählt wurde?

Gruesse,

ET

Hi, mache es doch so...

<html>

<body>

<script language="Javascript">

function pruefen(){

if( document.Auswertung.Auswahl[0].checked ){

window.navigate(document.Auswertung.Auswahl[0].value + "?monat=" + document.Auswertung.Monate.value + "&jahr=" + document.Auswertung.Jahre.value);

}

else{

window.navigate(document.Auswertung.Auswahl[1].value + "?monat=" + document.Auswertung.Monate.value + "&jahr=" + document.Auswertung.Jahre.value);

}

}

</script>

<form method="post" name="Auswertung" action="test">

<p>Geben Sie Ihre Zahlungsweise an:</p>

<p>

<input type="radio" name="Auswahl" value="Jahr.php"> Jahresauswertung<br>

<input type="radio" name="Auswahl" value="Monat.php" checked> Monatsauswertung<br>

Jahre<input type="text" name="Jahre" value=""><br>

Monate<input type="text" name="Monate">

</p>

<input type="button" value=" Absenden" onclick="pruefen();">

</form>

</body>

</html>

Hi,

deinem Formular fehlt die die Übergabemethode (post oder get)

Ansonsten kannst du Werte auch bei location.href an die Url anhängen.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.