2017-02-07 2 views
0

У меня есть этот яваскрипта код:HTML формы ввода

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

И этот HTML код:

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

Что я сделал не так?

ответ

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>

Уведомление закрывающие круглые скобки.

+0

Чтобы добавить к этому, идентификатор формы будет 'form', а не просто' formName'. –

+0

@MKemp Идентификатор действительно правильный, нас интересует значение поля ввода AFAIK. – ppajer

+0

Derp, вы правы :) Я взглянул на эту часть HTML. –

Смежные вопросы