表单提交不起作用,只刷新页面

时间:2015-12-12 15:16:19

标签: javascript html

当我点击提交按钮时,数据不会转到opiekunowie.php,而是只刷新页面。我不知道为什么。

<form id="opiekunform" method="post" autocomplete="off">
    <div class="formparent">
        <div class="formicon">
            <img style="width: 1.5vw; height: 1.5vw; margin-top: 0.9vw;" src="ikonki/email.svg">
        </div>
        <input id="opiekuninput" type="text" name="opiekun" placeholder="E-mail"/>
        <div class="error"></div>
        <div class="errorarrow"></div>
    </div>
    <div class="formparent">
        <input id="opiekunx" type="submit" value="Gotowe!" class="git" />
        <div class="error"></div>
        <div class="errorarrow"></div>
    </div>
</form>

Javascript:

var opiekunx = document.getElementById("opiekunx");
opiekunx.addEventListener("click", function eee()
{
    //if (document.getElementById("opiekuninput").value = "")
    //    document.getElementById("opiekuninput").value = "brak";

    document.getElementById("opiekunform").setAttribute("action", "opiekunowie.php");
    document.getElementById("opiekunform").submit();
}
, false);

1 个答案:

答案 0 :(得分:0)

问题是你没有在html中定义动作属性

更改此行的HTML

<form id="opiekunform" method="post" autocomplete="off">

使用此行

<form id="opiekunform" method="post" autocomplete="off" action="opiekunowie.php">

有关操作属性http://www.w3schools.com/tags/att_form_action.asp

的更多信息
相关问题