2017-02-07 1 views
0

Ich habe diesen Javascript-Code:HTML-Formular Eingabe

function othername() { 
    var input = document.getElementById("formName".value); 
    alert('Thanks for filling that out,' + ' ' + input + '!') 
} 

Und diesen HTML Code:

<form id="form" onsubmit="return false;"> 
<input type="text" id="formName"/> 
<input type="submit" onclick="othername();" /> 

Was habe ich falsch gemacht?

Antwort

3

<form id="form" onsubmit="return false;"> 
 
\t \t <input type="text" id="formName"/> 
 
\t \t <input type="submit" onclick="othername();" /> 
 
</form> 
 
<script> 
 
\t function othername() { 
 
\t \t var input = document.getElementById("formName").value; 
 
\t \t alert('Thanks for filling that out, ' + input + '!') 
 
\t } 
 
</script>

Beachten Sie die Schließung Pars.

+0

Um hinzuzufügen, ist die ID für das Formular 'Form' und nicht nur' FormName'. –

+0

@MKemp Die ID ist eigentlich richtig, wir interessieren uns für den Wert des Eingabefeldes AFAIK. – ppajer

+0

Derp, du hast Recht :) Ich habe einen Blick auf diesen Teil des HTML geworfen. –

Verwandte Themen