views:

13

answers:

2

Here is what I'm trying to do

<% form_for @color, :html => {:multipart => true, :name => "color_form"} do |f| %>
<%= f.text_field :head_color %>

and I want to use this javascript

document.color_form.color[head_color].value;

javascript obviously doesn't like this and throws an error. The problem is that I can't use text_field_tag. How can I get javascript to read this?

A: 

used getElementById, duh... much easier

jtmkrueger
+1  A: 

Your current code acts as if the DOM treats array_field[names] in any sort of special way, making document.color_form.color an array. Nope, it's not quite that clever.

You can still access the field by name, though, using bracket notation.

document.color_form["color[head_color]"].value
Matchu