unobtrusive-javascript

JavaScript/HTML: Wiring element events

I recently read a blog post. In it, the author told readers to wire up all their "onclick" events not inline, but when the DOM's ready, like this (jQuery example): <script type="text/javascript"> $(document).ready(function() { $("myElement").click(... }); </script> This, for all the elements on the page with events attached to the...

Help, "this" is confusing me in JavaScript

Working with the JavaScript one of the confusing thing is when using this var x = { ele : 'test', init : function(){ alert(this.ele); } } However when dealing with multiple object and especially events context of this changes and becomes confusing to keep track/understand. So if anybody has better inputs/guidelines/thoug...

Jquery Tabs 1.8 ajax content > #history problem

Hey! I'm trying to load jQuery content in the same container (div#realContent) and it seems that when I use the a 'title' to enter the div ID (all links the same title) the history stop working. You can enter here http://home.d23.com.uy/fermata/ user: fermata pass: fermata , and see what I mean. Thanks ...

unobtrusive javascript pain points to beware of

I have recently started learning unobtrusive JavaScript. Using JQuery its really fun. However with this thinking of writing JavaScript code has come a real long way from traditional ways. Also adding quick onclick="fun()" is helpful sometimes and as the application grows 100% unobtrusive code "sometimes" become difficult to write. Like ...

form.submit() missed by rails.js UJS observer

In a Rails 3 app, I want to make the browser call a remote function whenever a certain checkbox is toggled. In Rails 2, this was easy to do by passing :onclick => remote_function(...) to the checkbox helper. In Rails 3, the remote_* functions are deprecated, so I tried the following workaround: create a form around the checkbox usin...

Making a Method Globally Accessible in Javascript

given i have the following block of code (function(){ var mb = { abc:function(){ //do something }, xyz:function(width, height, site){ //do something } }; })(); how do i make the method mb.abc accessible from the page, but not mb.xyz? ...

What is the difference between globally declaring a function and using window.myfunc = myfunc

What is the difference between the following 2 examples of code: (function(){ var myFunc = (function(){ //do something })(); window.myFunc = myFunc; })(); and var myFunc = (function(){ //do something })(); ...

How do I create a random method name

I plan on using JSONP to call an external webservice to get around the fact that I dont want to create a global function that could potentially conflict with the calling page. I thought that creating a random function name and passing it up would work. Something like this: <script src="www.foo.com/b?cb=d357534"> where cb is the callb...

Jquery retrieve values of Dynamically created elements

Hi, I have a html page with a form. The form has Div which gets populated dynamically with Input elements like text box,radio,checkbox etc. Now I want to retrieve the values of these dynamically created elements in the Html page,so that i can submit it to a page. //HTML PAGE <script type="text/javascript"> $(function() { ...

Jquery CheckBox Selection/Deselection optimally given X checkboxes

Hi guys, I have suppose say 'X' check-boxes(any input elements) in a Form and "M" option selection indexes ("M" less than equal to "X"). then how do i select the "M" option indexes/values and deselect the rest of check-boxes optimally? i.e.Suppose I have 10 Checkboxes and 5 Option Indices(eg: 1,2,4,5,8) then i have to select checkboxes...

jquery for ruby on rails

Hello, I am tying to use this code http://gist.github.com/110410 to dump Prototype in favor of jQuery but I do have a problem. This is my HTML (a link_to generated link): <a onclick="var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var s = documen...

Rails: Rails Prototype vs Unobtrusive Javascript using jQuery

I have worked on two projects using Ajax and Ruby. In one project, I used Rails Prototype helpers and RJS. In the other project I used HAML and unobtrusive Javascript with jQuery. Each had a learning curve which I have overcome. However, the long-term costs and benefits of either approach are not clear. For my next project I am trying to...

Manipulate multiple check boxes by ID using unobtrusive java script?

I want to be able to select multiple check boxes onmouseover, but instead of applying onmouseover to every individual box, I've been trying to work out how to do so by manipulating check boxes by ID instead, although I'm not sure where to go from using getElementById,. So instead of what you see below. <html> <head> <script> var T...

How Does Rails 3's "data-method='delete'" Degrade Gracefully?

Rails 3 does some cool stuff to make Javascript unobtrusive, so they've done things like this: = link_to "Logout", user_session_path, :method => :delete ..converts to <a href="/logout" data-method="delete" rel="nofollow">Logout</a> But it just occurred to me.. When I turn off javascript the method isn't DELETE anymore, it's GET as ...

Rails3 UJS example with unobtrusive dry flash error

Hi to everybody thislink text is a demo "done right" about rails3 and UJS, but if you add: validates :name, :presence => true to the Task model that error(500 Internal Server Error) is displayed nowhere. Do you know a correct and clean way to handle it? ...

rails best practices where to place unobtrusive javascript

Hi there, my rails applications (all 2.3.5) use a total mix of inline javascript, rjs, prototype and jquery. Let's call it learning or growing pains. Lately i have been more and more infatuated with unobtrusive javascript. It makes your html clean, in the same way css cleaned it up. But most examples i have seen are small examples, an...

How to check browser for touchstart support using JS/jQuery?

In an attempt to follow best practices, we're trying to use the proper JavaScript/jQuery events according to what device you are using. For example, we're building a mobile site that has an tag that will have an onclick or touch event. In the case of an iPhone, we'd like to use the "touchstart" event. We'd like to test if their device s...

Unobtrusive Toggling failing in Rails

I've been at this for hours but it just isn't working. I'm trying to get ToggleJS working using Scriptaculous' Effects library. Specifically, the example: http://wiseheartdesign.com/page_attachments/0000/0075/demo.html. I got it working beautifully using a pure html file called new.html. I then converted it to new.html.erb so I can inco...

Unobtrusive Toggling in a Loop

Hi everyone, I'm using Unobtrusive Toggling in a view that contains many records (Orders). I've got it working on individual divs, but I now want it to work so each Order can be expanded/contracted individually within the loop using its own toggle link (the link is also looped). When my expandable div is called x, the problem is every ...

Generating unobtrusive JS

I have read quite a bit about unobtrusive JS and how to generate it and all that jazz... My problem is this: I have a website that heavily relies on mod_rewrite, so essentially all the pages requests are sent to index.php that generates the main structure of the page and then includes the appropriate page. Now, there are different secti...