AJAX Form Field Values Not Updating
I'm trying to make a simple AJAX HTML form. Here is an HTML snippet:
- <form>
- <fieldset>
- <legend>Character Groups</legend>
- <ul>
- <li>
- <label for="lowerLetters">Lower Case Letters</label>
- <input name="lowerLetters" type="checkbox" checked="checked" required="required" value="on" />
- </li>
- <li>
- <label for="upperLetters">Upper Case Letters</label>
- <input name="upperLetters" type="checkbox" checked="checked" required="required" value="on" />
- </li>
- <li>
- <label for="numbers">Numbers</label>
- <input name="numbers" type="checkbox" checked="checked" required="required" value="on" />
- </li>
- <li>
- <label for="symbols">Symbols</label>
- <input name="symbols" type="checkbox" checked="checked" required="required" value="on" />
- </li>
- </ul>
- </fieldset>
- <fieldset>
- <legend>Password Length Settings</legend>
- <ul>
- <li>
- <label for="minimumLength">Minimum Password Length</label>
- <input type="text" name="minimumLength" size="3" required="required" value="8" />
- </li>
- <li>
- <label for="maximumLength">Maximum Password Length</label>
- <input type="text" name="maximumLength" size="3" required="required" value="12" />
- </li>
- </ul>
- </fieldset>
- <p><input type="submit" value="Generate" /></p>
- </form>
- <p><span id="output" /></p>
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
- <script type="text/javascript" src="/resources/ajax.js"></script>
The file ajax.js is quite simple:
- $(document).ready(function () {
- var query = $('form').serialize();
- $('form').submit(function () {
- $.get('/demo/password', query, function (result) {
- $('#output').html(result);
- alert(query);
- });
- return false;
- });
- });
The problem is that the query string that gets sent, as shown by the alert, is
always "lowerLetters=on&upperLetters=on&numbers=on&symbols=on&minimumLength=8&maximumLength=12", regardless of what fields I check/uncheck or edit after the page loads in the live form. In other words, if I load the page, change the "minimumLength" field to "12", and submit the form, it still sends the above string instead of "lowerLetters=on&upperLetters=on&numbers=on&symbols=on&minimumLength=12&maximumLength=12". If I remove the "value=*" attributes in the HTML, the string behaves similarly, except with zero-length strings instead of the specified default values, resulting in the same problem.
Does anyone have any idea what I'm doing incorrectly? I'd be happy to provide any additional information that might be of help. Thanks in advance!