SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    a complex form with checkboxes and ajax...

    I need to build a form with various fields that are checkboxes and each of which if checked reveal other text fields for example. How can ii do that? do i have to use ajax? If so is there a way to make an ajax request when a particular checkbox is checked to add other related fields on the fly?

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use Ajax, but you probably don't have to. Your application will be snappier if you don't use Ajax. The Prototype library is bundled with Rails [1]. You can put the hidden form fields in hidden divs and make them appear with Element.show if the user clicks a checkbox.

    RJS is a very interesting technology for Ajax applications [2], use it if you have to get data from your database to determine which fields should appear. This will be slower because new data has to be downloaded from the server.

    [1] http://www.prototypejs.org/
    [2] http://www.rubyinside.com/16-rjs-res...rammers-5.html

  3. #3
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Fenrir2 View Post
    You can use Ajax, but you probably don't have to. Your application will be snappier if you don't use Ajax. The Prototype library is bundled with Rails [1]. You can put the hidden form fields in hidden divs and make them appear with Element.show if the user clicks a checkbox.

    RJS is a very interesting technology for Ajax applications [2], use it if you have to get data from your database to determine which fields should appear. This will be slower because new data has to be downloaded from the server.

    [1] http://www.prototypejs.org/
    [2] http://www.rubyinside.com/16-rjs-res...rammers-5.html
    thanks for that but i have a question now that i think of it many times. Is there a way to use unobtrusive javascript with rails? Rails javascript/ajax helpers put the javascript code in the middle of the html and it is not accessible etc.

  4. #4
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code in the middle of html is not a big problem since you don't read the HTML, you read the Ruby (and it's nicely abstracted in Ruby).

    You can keep the site accessible by providing a non-ajax interface to your site if the browser has js turned off.

  5. #5
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Fenrir2 View Post
    Code in the middle of html is not a big problem since you don't read the HTML, you read the Ruby (and it's nicely abstracted in Ruby).

    You can keep the site accessible by providing a non-ajax interface to your site if the browser has js turned off.
    in the generated html there is javascript code in the middle of the html itself


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •