Hi everyone,

I am trying to create a module which will have users create their own search clause based on different options.

I would like to know how to transfer data between form elements in a form that has already been rendered.

http://www.planckprototypes.com/images/form.JPG

The form will contain a list box, text box and 2 buttons

- In the image attached, there is a textbox in which the user types a value.
- He then clicks on add to add the word in the text box to a listbox below it
- He repeats the process to add multiple values into the list
- He can also click on an item in the list and remove it by clicking on the remove button.

Does anyone know how to implement this. Does the Forms API have functions to do this. Any help would be greatly appreciated.
Oh and by the way, I am a noob :)

Aurian

Comments

zbricoleur’s picture

My first thought is that you are making it unnecessarily complicated. Just have the user type the words he wants, separated by spaces, into a text field. I don't see what the second field adds (other than headaches).

That said, if you want to move values around in the form interactively, that's a job for javascript.

Aurian Noreinor’s picture

I was just outlining the basic structure.

The textbox will also have an autocomplete feature.

As the user gets 1 item (with autocomplete) he assigns a value to it like Smith=2 and adds it to the listbox. He keeps adding these item value pairs and when he submits, there is a query which will run an AND condition on the database using each item in the list.

Is this only possible with javascript ?
Could you point me to any tutorials on how to embed such javascript in drupal?

kannan@kiluvai.com’s picture

You know jquery, it is very easy with jquery, http://blog.jeremymartin.name/2008/02/easy-multi-select-transfer-with-jq... this tutoeial explains how to move text from one list box to other, but you can use the same and modify the code to get the value from the textbox.

with regards
Kamalakannan S.

Aurian Noreinor’s picture

Kamalakannan,

Thanks so much for your help. I was looking for something just like this. Now I can add the code to my module.js file and have drupal insert it when the form is being created.

Again, Thanks for your help