Note that there are some explanatory texts on larger screens.

plurals
  1. PO"Submit" Form and Direct to Javascript Generated URL
    primarykey
    data
    text
    <p>I have a login form that, when completed, sends users to a page with a JavaScript generated URL (allowing me to pass a JavaScript variable to my PHP script using $_GET). However, in order to do that, the Login button is currently 'type="button"'. While everything works, it means that users cannot login by hitting Enter; they must actually click the Login button. Is there a way I can "Submit" the form, while still having it point to the JavaScript generated URL?</p> <p>This seems like a pretty basic concept, which tells me I might be approaching it the wrong way to begin with. Any guidance is appreciated.</p> <p>HTML:</p> <pre><code>&lt;form name="login"&gt; Username: &lt;input type="text" name="user_id"/&gt; Password: &lt;input type="password" name="pswrd"/&gt; &lt;input type="button" onclick="check(this.form)" value="Login"/&gt; &lt;/form&gt; </code></pre> <p>JavaScript:</p> <pre><code>function check(form) { var userCredentials = [["jsmith", "smithpassword", "John Smith"], ["jdoe", "doepassword", "Jane Doe"]]; var credCheck = 0; for (var i = 0; i &lt; userCredentials.length; i++) { if (userCredentials[i][0] == form.user_id.value) { credCheck += 1; var displayName = userCredentials[i][2]; if (userCredentials[i][1] == form.pswrd.value) { window.open("home.php?display_name=" + displayName, "_self"); } else { alert('The username and password do not match.'); return false; } } } if (credCheck == 0) { alert('The username entered is not valid.'); return false; } else { return true; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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