Home arrow JavaScript arrow Dynamically Generate a Selection List in a Rails Template
JAVASCRIPT

Dynamically Generate a Selection List in a Rails Template


If you're tired of the usual ways in which AJAX generates web widgets, read this article for something new. It lets the user choose the content of the pop-up. This article is excerpted from hack 58 of the book Ajax Hacks, written by Bruce W. Perry (O'Reilly; ISBN: 0596101694). Copyright © 2007 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

Author Info:
By: O'Reilly Media
Rating: 5 stars5 stars5 stars5 stars5 stars / 7
July 31, 2008
TABLE OF CONTENTS:
  1. · Dynamically Generate a Selection List in a Rails Template
  2. · Work with Ajax and Ruby on Rails
  3. · Rendering the HTTP Response
  4. · A Little Partial Pizzazz

print this article
SEARCH DEVARTICLES

Dynamically Generate a Selection List in a Rails Template
(Page 1 of 4 )

Hack 58  Generate a selection list from server-side data using Ajax and Ruby on Rails.

This hack creates aselectelement from server-side data using a Ruby on Rails application. Unlike the typical manner in which a web widget is generated in a web page, the user chooses the content for the pop-up, and then the pop-up appears out of the blue, without anything else on the page changing. The selections that the user sees in the pop-up derive from a server-side component; they are not just hard-coded JavaScript or HTML that is part of the web page.

This hack has the same behavior as some of our earlier hacks, but the path our code takes to produce its effects is quite different. A Rails application wraps all of theXMLHttpRequestmechanics behind its own methods. Figure 7-9 shows what the web page looks like. The user reaches this page by typing http://localhost:3000/hacks/ into a web browser’s location field.

We’re using the WEBrick server that comes with Ruby on Rails.


Figure 7-9.  Cop your own pop-up

The user chooses either Team or Individual from the pop-up and clicks the Show Sports button, and anotherselectlist (whose values are determined by the user’s choice in the first list) appears just above the button.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- Project Nashorn to Make Java, JavaScript Wor...
- JavaScript Virus Attacks Tumblr Blogs
- Google Releases Stable Dart Version, JavaScr...
- Khan Academy Unveils New JavaScript Learning...
- Accessing Nitro? There`s an App for That
- JQuery 2.0 Leaving Older IE Versions Behind
- Fastest JavaScript Engine Might Surprise You
- Microsoft Adjusting Chakra for IE 10
- Brendan Eich: We Don`t Need Google Native Cl...
- An Overview of JavaScript Statements
- An Overview of JavaScript Operators
- Overview of JavaScript Variables
- More of the Top jQuery Social Plugins
- The Top jQuery Social Plugins
- More of the Top jQuery Slider Plugins

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials