1

I need to output some javascript codes as well as form fields.

I am using Drupal 6 and form API to build the form. How can I output those javascript codes? Is there a 'javascript' type like textfield/checkboxes ?

I have tried the code below but string 'Array' is printed on the page instead of js code:

$form['target'] = array(
'#prefix' => '<div id="newuser">' ,
'#value' => drupal_add_js('alert("hello)','inline'),
'#suffix' => '</div>'

);

1 Answer 1

2

drupal_add_js() is for adding script tags to the page. It doesn't go in a form element.

 drupal_add_js('alert("Hello!")', 'inline');

would go by itself on a line. This would add that javascript to the page, so when the page loads you would get a pop-up that says "Hello".

and/or to add markup to the page you would do this:

$form['target'] = array(
  '#prefix' => '<div id="newuser">',
  '#value' => t('Hello'),
  '#suffix' => '</div>'
);

Which would add the text "Hello" to the form in the newuser div.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.