Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By ghosty on
Hi, I'm trying to change the content of the body field with some default text whenever someone changes an option in the form's select drop down menu. I added the select field using CCK. It looks like something is trying to happen, but I just don't know how to access the content of the body field the correct way to change it's value. Any ideas?
Thanks!
Comments
Hi, do you have some code
Hi,
do you have some code to put here, maybe it will help...
Vasi.
I'm trying to actually do it
I'm trying to actually do it another way now, but still having issues. What I'm trying to do now is somehow let the form go through validation, then replace the content in the body textarea. So here are the steps I would like to do:
1. Person fills form out, chooses option from select field which submits the form.
2. Form goes through custom validation, acknowledges that the select field submitted the form?
3. Depending which select option was chosen, change the content in the body textarea with some default text.
4. Form is once again displayed, but now with updated body textarea content.
5. Person clicks the submit button to finish off the form.
Any way this can be done? I think the tough parts for me is part #2 and #3. I know there are ways to submit a form using a select field, but how can you tell if the form was submitted by the select field or the submit button?
Ok, I got part 2 working, now
Ok, I got part 2 working, now I just need to worry about part 3. Is there a way I can change the content of the body textarea field and and send the person back to the form page with the new content in the body?
So I'm using form_set_value()
So I'm using form_set_value() to try and change the value of the body field, but it only works once the form submits. If the form comes back after validation, then the value I set in form_set_value() is replaced by the original value the form editor filled in. Is there any way to get around this? Really, all I want to do is set some default text in the body field depending on what the editor chose in a drop down field. It doesn't sound too complicated to me, done it many times with php but with Drupal it seems like a total pain.
Solved
I solved my problem with some jQuery.