Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8149483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:51:41+00:00 2026-06-06T14:51:41+00:00

I have a form with a textfield element which when a user starts typing

  • 0

I have a form with a textfield element which when a user starts typing into I want to pre-populate a different element.

I’ve been using the #ahah attribute which works fine with the event property set to ‘keyup’ however I lose focus on the textfield element because the moment the ‘keyup’ event is fired the whole form is rebuilt due to ahah’s behaviour.

I tried setting the event property to ‘change’ and that works nicely however in order for the ‘change’ event to fire I need to click away from the textfield – so from UI point of view I cannot expect users to click away from field just to get the results to display.

I’m not sure if it’s possible to achieve what I want with AHAH which is fine but I’d like to stick with it if possible.

Happy to provide code if required and sorry if it’s not clear, quite difficult to explain.

Thanks
Steve

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:51:42+00:00Added an answer on June 6, 2026 at 2:51 pm

    The whole form shouldn’t be re-rendered by the browser. That’s precisely the idea AHAH, that you can update just part of a form. Make sure to set the “wrapper” attribute (of the #ahah attribute) to the ID (as in: the HTML attribute) of the DOM element that you want Drupal’s JS functionality to update asynchronously.

    For example:

    <?php
    function MYMODULE_some_ahah_enabled_form(&$form_state) {
    
      $initial_markup = '<div>' . t('This content will be replaced') . '</div>';
    
      $form['dynamic_thing'] = array(
        '#type' => 'markup',
        '#prefix' => '<div id="dynamic-thing">', // Set Drupal's AHAH wrapper to this ID
        '#suffix' => '</div>',
        '#value' => $initial_markup,
      );
    
      $form['field_which_will_trigger_ahah_behavior'] = array(
        '#type' => 'textfield',
        '#ahah' => array(
          'path' => 'MYMODULE/path/to/ahah/callback',
          'wrapper' => 'dynamic-thing',
          'event' => 'keyup',
        ),
        '#default_value' => 'Change me',
      );
    
      return $form;
    }
    
    /**
     * Your menu callback (which is declared in your hook_menu()) which returns only the HTML that will replace the existing markup in $form['dynamic_thing'].
     */
    function MYMODULE_ahah_callback() {
      $output = '<div>New content for the dynamic thing</div>';
      drupal_json(array('status' => TRUE, 'data' => $output));
      exit();
    }
    

    Your “field_which_will_trigger_ahah_behavior” DOM element in the browser shouldn’t lose focus, or be re-rendered in any way, unless there’s something else causing some bug.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created one jsp form which contains the username textfield. On the click
i have a form which user enters some data, could be checkboxes, radio buttons,
I have a form here in which there is a textfield which contains a
Hi I have a form class which looks like below:- class UserCreateForm(wtf.Form): name=wtf.TextField('Name',validators=[validators.Required(),username_check]) email=wtf.TextField('Email')
I want to have a Form that can Add or Delete TextFields. I was
I have form with few buttons and I want to know what button is
I have form where user submits field. Field can have letters, numbers, and punctuation.
I have form in my page, I am using ajax.beginform(). Inside this form I
I have form with multiple input type=radio with text next to them. I want
I have been developing some Django app and there's some duplicated code for different

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.