Guest User

Untitled

a guest
Aug 18th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. Drupal 7 JS code through the AJAX
  2. $form['myitem'] = array(
  3. '#type'=>'textfield',
  4. '#ajax' => array(
  5. 'callback' => 'my_callback',
  6. 'wrapper' => 'new-id',
  7. 'method' => 'html',
  8. 'effect' => 'fade',
  9. ),
  10. );
  11. $form['myitem2'] = array(
  12. '#type'=>'markup',
  13. '#value'=>"<div id='new-id'> I'm #new-id </div>"
  14. );
  15.  
  16.  
  17. function my_callback(&$form, &$form_state){
  18. $commands = array();
  19. $commands[] = ajax_command_invoke('#new-id', 'html', array('<div id="new-id2">#new.id2 here!</div>'));
  20. $commands[] = ajax_command_invoke('#new-id2', 'addClass', array('error'));
  21. return array('#type' => 'ajax', '#commands' => $commands);
  22. }
Add Comment
Please, Sign In to add comment