Quoting Seth Freach <sfreach@gmail.com>:
Earnie,
If you have a simple form as follows: <form> <input type="text" id="alpha" class="check-on-change" /> <input type="text" id="beta" class="check-on-change" /> <input type="text" id="gamma" /> </form>
to do a simple auto population of the third field based on the sum of the first two with jquery would look like this: <javascript> $(document).ready(function() { $('.check-on-change').change(show_sum); });
function show_sum() { var a = $('#alpha").val(); var b = $('#beta").val(); $('#gamma').val(a + b); } </javascript>
In jQuery, you access DOM elements with "selectors", which are strings that follow the exact same syntax as CSS, but wrapped in "$(...)". Once you have accessed them like this, you can perform functions on them such as .val() with no params to /get/ the current form field value, or val(x) with a parameter to /set/ the value.
the first bit, "$(document).ready(function(){...});, set's everything up to work after the DOM has been loaded.
see http://docs.jquery.com/Core, and in particular the section on the left of that page titled "API Reference" for lots more info.
Thanks, Seth. You've got me started and I'm thinking I need to also add ['#ahah'] to my forms. I'm still confused by the various API but I'll muddle through it now. -- Earnie -- http://r-feed.com/ -- http://for-my-kids.com/ -- http://www.4offer.biz/ -- http://give-me-an-offer.com/