Search code examples
javascriptruby-on-railsajaxformspreview

Creating a Preview for a form, like google adwords


So I am making a simple form form customers to fill out, and I want users to get a preview of what their submission will look like. A great example of this is google adwords, when you are creating a new ad.

Basically this has to be done through ajax, updating the preview div depending on what the user has entered into the form fields. I figured I could do an onChange function that updates the div, but I believe that only works when the user finishes with that field and moves on to another one, which is fine, but it would be nice if it could happen in real time, as the user types in that field.

What should I look into to go about doing this?

It may or may not having some bearing, but I am using Rails 3.

Thanks!


Solution

  • Even if you're not using jQuery, this will help to understand onChange: http://api.jquery.com/change/

    Your approach with having a preview div sounds ok. Inside this div you can map other divs (or any tags) to each input.