简体   繁体   English

来自javascript的变量不会传递到表单

[英]Variable from javascript wont get passed on to the form

The variable ocode does not get passed to the def resetusername. 变量ocode不会传递给def resetusername。 document.getElementById("ocode").value gets the value from storageName and I verified it by using 'alert' function. document.getElementById(“ ocode”)。value从storageName获取值,我通过使用“警报”功能对其进行了验证。 Can anyone please tell me what I am doing wrong.Thank you 谁能告诉我我在做什么错了。谢谢

 function mySubmit() {

         document.getElementById("ocode").value = 
         localStorage.getItem("storageName");
         alert(document.getElementById("ocode").value);
         document.getElementById("myform").action = "/postresetusername/";

  }


 <form  method="post"  id="myform" onsubmit="mySubmit()">
 {% csrf_token %}
      <div class = "login-box">
      <h1>Reset Username</h1>

      <div class = "textbox" style="float:left">
          <input type = "email"     placeholder="Previous Email"  name = "email" id="email">
      </div>


     <input type='hidden' id= "ocode" name='id' value="">






 def postresetusername(request):
    email = request.POST.get('email')
    ocode = request.POST.get('ocode')
    authe.verify_password_reset_code(ocode, "new_pwd")
          return render(request, "signIn2.html", {"messg": "Password reset"})
 return render(request, "signIn2.html", {"messg": "Cant reset"})

Forms inputs use the name and you are using the id. 表单输入使用名称,而您使用的是id。

<input type='hidden' id= "ocode" name='id' value="">
                                 ^^^^^^^^^

and the backend is using 后端正在使用

ocode = request.POST.get('ocode')
                          ^^^^^

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM