=== modified file 'includes/form.inc'
--- includes/form.inc	2007-10-16 14:06:23 +0000
+++ includes/form.inc	2007-10-18 08:12:50 +0000
@@ -1821,11 +1821,24 @@ function theme_textfield($element) {
 }
 
 /**
+ * Preprocess forms by loading their scripts.
+ */
+function template_preprocess_form($element) {
+  foreach($element['#scripts'] as $key => $script) {
+    call_user_func_array('drupal_add_js', $script);
+  }
+}
+
+/**
  * Format a form.
  *
  * @param $element
  *   An associative array containing the properties of the element.
- *   Properties used: action, method, attributes, children
+ *   Properties used: scripts, action, method, attributes, children.
+ *
+ *   If $form['#scripts'] is populated, each element in its array
+ *   will be passed on to drupal_add_js() for inclusion in the final
+ *   rendered page.
  * @return
  *   A themed HTML string representing the form.
  */

=== modified file 'modules/poll/poll.module'
--- modules/poll/poll.module	2007-10-17 19:36:12 +0000
+++ modules/poll/poll.module	2007-10-18 08:08:05 +0000
@@ -238,9 +238,13 @@ function poll_form(&$node, $form_state) 
     ),
   );
 
-  // If we're using the javascript version (99% use-case), change the button
-  // title to 'Add another choice' to reflect the javascript behavior.
-  drupal_add_js("if (Drupal.jsEnabled) { $(document).ready(function() { $('#edit-poll-more').val('". t('Add another choice') ."'); }); }", 'inline');
+  // Change the button title to reflect the behavior when using JavaScript.
+  // We put this in $form['#scripts'] so it will be passed on to drupal_add_js()
+  // whenever the form is rendered, not just the first time it's built.
+  $form['#scripts']['poll_more'] = array(
+    'data' => 'if (Drupal.jsEnabled) { $("#edit-poll-more").val("'. t('Add another choice') .'"); }',
+    'scope' => 'inline',
+  );
 
   // Poll attributes
   $_duration = array(0 => t('Unlimited')) + drupal_map_assoc(array(86400, 172800, 345600, 604800, 1209600, 2419200, 4838400, 9676800, 31536000), "format_interval");

=== modified file 'modules/system/system.module'
--- modules/system/system.module	2007-10-17 21:59:31 +0000
+++ modules/system/system.module	2007-10-18 08:08:05 +0000
@@ -126,7 +126,7 @@ function system_perm() {
  */
 function system_elements() {
   // Top level form
-  $type['form'] = array('#method' => 'post', '#action' => request_uri());
+  $type['form'] = array('#method' => 'post', '#action' => request_uri(), '#scripts' => array());
 
   // Inputs
   $type['submit'] = array('#input' => TRUE, '#name' => 'op', '#button_type' => 'submit', '#executes_submit_callback' => TRUE, '#process' => array('form_expand_ahah'));

