javascript - Show a DIV with form data on submit -


Maybe I'm stupid I'm submitting a hidden divate with the values ​​of a form on submission.

The DIV opens with the right data, but then resets the page after reloading. What am I doing wrong?

Here's my test:

  & lt; Html xmlns = "http://www.w3.org/1999/xhtml" & gt; & Lt; Top & gt; & Lt; Meta http-equiv = "content-type" content = "text / html; charset = us-ascii" /> & Lt; Title & gt; Test & lt; / Title & gt; & Lt; Script type = "text / javascript" & gt; Function Test () {var usr = document.getElementById ('Users'). Values; Var pwd = document.getElementById ('passwd') value; Document.getElementById ('out'). InnerHTML = usr + "" + pwd; Document.getElementById ('out'). Style.display = "block"; Back true; } & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Form action = "" onsubmit = "return exam ()" & gt; & Lt; Input type = "text" id = "user" name = "user" /> & Lt; Input id = "passwd" type = "text" name = "passwd" /> & Lt; P & gt; & Lt; Input type = "submit" value = "go" /> & Lt; / P & gt; & Lt; / Form & gt; & Lt; Div id = "out" style = "display: none;" & Gt; & Lt; / Div & gt; & Lt; / Body & gt;  

short answer:

Change it

  Come back to the truth;  

this

  return false;  

Long answer:

Form submissions are designed to load a new page. However, with scripting we can stop this event from stopping. It can be obtained in many ways, but for your example, the event will only be canceled if you return "false" to your handler, but only if onsubmit attribute Also returns the statement (which you already had).


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -