简体   繁体   中英

Variable from javascript wont get passed on to the form

The variable ocode does not get passed to the def resetusername. document.getElementById("ocode").value gets the value from storageName and I verified it by using 'alert' function. 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.

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

and the backend is using

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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