Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to prevent the default submit action </p> <p>in pure JavaScript it's </p> <pre><code>form.addEventListener('submit',resetpassword,false) function resetPassword(event){ event.preventDefault(); //your code here } </code></pre> <p>this works on the button but also if you press the enter button.</p> <p>in jquery its somehting like this..</p> <pre><code>$('form').submit(function(e){resetPassword(e);return false}) resetPassword(e){ e.preventDefault(); // your code } </code></pre> <p><strong>EDIT</strong></p> <p>The FORM when submit button is clicked or enter button is pressed</p> <p>will trigger the event 'submit'</p> <p>so if you remove the function caller from button</p> <p>and add it to the form </p> <p>you can press enter or click submit</p> <p>in both cases it will execute your function</p> <p>inside your function</p> <p>the first argument in pure javascript and prolly also in jquery is the event</p> <p>you need to stop that default event</p> <p>and you do that with the ntive function </p> <pre><code>event.preventDefault(); </code></pre> <p>so:</p> <pre><code>$('form').onsubmit(function(e){ e.preventDefault(); var user = document.getElementById('username').value; var password = document.getElementById('password').value; var conf = document.getElementById('confirm').value; var code = document.getElementById('code').value; if(code.length == 0 || password.length == 0 || user.length == 0 || conf.length == 0) { alert("Entries empty"); } else if(password != conf) { alert("Passwords don't match"); } else { $.ajax({ type: "POST", url: "scripts/changepassword.php", data: {Username: user, Password: password, Code: code}, dataType: "jso.................. </code></pre> <p>and your html</p> <pre><code>&lt;form&gt; &lt;input id="username" placeholder="Username" name="username" type="text" /&gt; &lt;input id="password" placeholder="Password" name="password" type="password" /&gt; &lt;input id="confirm" placeholder="Confirm Password" name="confirm" type="password" /&gt; &lt;input id="code" placeholder="Code" name="code" type="text" /&gt; &lt;div class="registrationFormAlert" id="incorrectEntry"&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;input class="btn" id="signinbut" value="Reset" type="submit" style="width:28%;" /&gt; &lt;/form&gt; </code></pre> <p>Now said that take a look at pure javascript (maybe not compatible with all browsers) <a href="http://caniuse.com/xhr2" rel="nofollow">http://caniuse.com/xhr2</a></p> <pre><code>document.getElementsByTagName('form')[0].addEventListener('submit',function(e){ e.preventDefault(); // validate form here else return or alert something var xhr = new XMLHttpRequest; xhr.open( 'POST' , YOURURL ); xhr.onload = function (){ alert('success') }; xhr.send( new FormData( this ) ) } , false ); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload