     markup do
       model_name = Map.get(resource, :__struct__, "") |> base_name |> Inflex.parameterize("_")
       action = get_action(conn, resource, mode)
-
+      scripts = ""
       Xain.form "accept-charset": "UTF-8", action: "#{action}", class: "formtastic #{model_name}", 
           id: "new_#{model_name}", method: :post, novalidate: :novalidate  do
 
         build_hidden_block(conn, mode)
-        build_main_block(conn, resource, model_name, items) 
+        scripts = build_main_block(conn, resource, model_name, items) 
+        |> build_scripts
         build_actions_block(conn, model_name, mode) 
       end 
-      if script_block do
-        Xain.text "\n"
-        Xain.script type: "text/javascript" do
-          text "\n" <> script_block <> "\n"
-        end
-      end
-    end
-  end
+      put_script_block(scripts)
+      put_script_block(script_block)
+    end
+  end
+
+  defp put_script_block(script_block) do
+    if script_block do
+      Xain.text "\n"
+      Xain.script type: "text/javascript" do
+        text "\n" <> script_block <> "\n"
+      end
+    end
+  end
+
+  defp build_scripts(list) do
+    head = "$(document).ready(function() {\n"
+    script = for i <- list, is_tuple(i), into: head, do: build_script(i)
+    script <> "});"
+  end
+
+  defp build_script({:change, %{id: id, script: script}}) do
+    """
+    $('##{id}').change(function() {
+      #{script}
+    });
+    """
+  end
+  defp build_script(other), do: ""
+
   defp get_action(conn, resource, mode) do
     case mode do 
       :new -> 

       opts: %{collection: collection}} = item, _resource, model_name, errors) do
    errors = get_errors(errors, field_name)
    label = Map.get item[:opts], :label, field_name
    wrap_item(field_name, model_name, label, errors, fn(ext_name) -> 
      if Enum.all?(collection, &(is_binary(&1) or (is_tuple(&1) and (tuple_size(&1) == 2)))) do 
        build_select_binary_tuple_list(collection, item, field_name, resource, model_name, ext_name) 
      else

    for item <- schema do
      build_item(item, resource, model_name, errors)
    end
    |> flatten
  end

  defp flatten(list) when is_list(list), do: List.flatten(list)
  defp flatten(other), do: [other]

  @hidden_style [style: "display: none"]

  def wrap_item(field_name, model_name, label, error, contents) do
    ext_name = "#{model_name}_#{field_name}"
    {label, hidden} = case label do
      {:hidden, label} -> 
        {label, @hidden_style}
      label when label in [:none, false] -> 
        {"", @hidden_style}
      label -> 
        {label, []}
    end

    error = if error in [nil, [], false], do: "", else: "error "
    li([class: "string input optional #{error}stringish", id: "#{ext_name}_input"] ++ hidden) do
      label(".label #{humanize label}", for: ext_name)
      contents.(ext_name)
    end
    ext_name
  end

  defp build_select_binary_tuple_list(collection, item, field_name, resource, model_name, ext_name) do
