Jump to content

[SOLVED] About a dynamic form


weekenthe9

Recommended Posts

[Field Name]: [textbox]

[Field Name]: [textbox]

[Field Name]: [textbox]

....

[Field Name]: [a drop down list] [add button] [current list, not editable]

[Field Name]: [textbox]

[submit button]

 

There's nothing special about this form about the red line. Here's what I want this line to do:

 

Let's say if the dropdown list has 3 values: Red, Green and Blue. if I select "Red" and click the "Add" button beside it, the form would reload with all the values I previously entered, but the [current list, not editable] is now "Red".

 

Now if I select "Green" and click "Add", the form would reload again, with all the values I previously entered, and the [current list, not editable] should now be "Red, Green".

 

After I'm done with adding stuff from the dropdown list, I will click "Submit" button on the bottom of the page, and all the field I entered, as well as the "Red, Green" list would be sent to a next page which will record these information into database.

 

I'm not sure about how I should code that red line. I know this sounds really confusing, but I can't really find a good way to express it. If you're willing to help but not sure about what I'm asking, please feel free to ask

 

Thanks a lot!

Link to comment
Share on other sites

Hi

 

If you want to do it in php (rather than Javascript) then have a submit button for the full submit and another for just adding a selection from the drop down list. When they just add a selection then you store the selection in a hidden field and put it out in plain text / locked textarea (and also loop through any existing hidden fields of that data outputting it to the plain text / locked textarea as well).

 

Then when they finally press the real submit button you can process the form normally, getting all the previous selections from the hidden fields.

 

That said you could do this with Javascript. An example of dynamically adding hidden fields using Javascript is here. The "Add" links each add a hidden field using a Javascript function  (called addElement()). You could do a very similar thing using an onclick event in the select.

 

All the best

 

Keith

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.