Adding dynamically form fields depending on selection of combo box with Javascript?

First, I would suggest that you learn to work with JQuery (javascript library).

Up vote 0 down vote favorite share g+ share fb share tw.

I have to make a information submission page for a website, where will have some fields which should be generated on the value after selection of combo box value. Like if we select "2" from the value of combo box, two personal details fields should be generated. Later I have to instert these values in DB with help of PHP.

I have to put validations too for these generated fields. There are many fields which I have to use something like it. But I have to start with it.

Please help me with it or give me some links where I can get some help regarding this. Thanks. Php javascript html validation link|improve this question asked Mar 2 at 18:59Rajeev Kumar73 75% accept rate.

First, I would suggest that you learn to work with JQuery (javascript library). api.jquery.com/ docs.jquery.com/Plugins/Validation docs.jquery.com/UI/Autocomplete I've wound up doing something rather similar to what you describe using jquery UI autocomplete, clone, reposition, and validation functionality, and it's all relatively straightforward. Essentially, what you'd do would be use jquery validate (a jquery plugin)) on the form, put in a jquery UI autocomplete for your combobox with an onchange, and have all of the details fields that you might want to include in hidden divs outside of the form.

When the combobox changes, it calls a function that destroys fields as necessary, then clones blank fields from outside the form, populates them (if need be) and inserts them into appropriate places inside the form. The validator runs on the class attribute, so just making sure that the new fields have the right class will be enough to include them in the validation. Jquery and its plugins function pretty much everywhere that standard javascript does, so it shouldn't be that hard to integrate.

There's a bit of spin-up time as you figure out how to do stuff, but it sounds like you'll have a fair amount of that anyway, and it'll make things a lot easier in the medium-to-long-term.

I will assume your combo will be identified with ". ValueCount" and that the default amount elements is one, which can be found under ". Field".

The general container of it all is identified by "fieldgroup" Your first field must have the name set to something like dynamicfield. Replace "dynamicfield" with whatever you want. Then use jQuery to create a prototype for your first field: var $prototype = $(".

Field").clone(); Note that . Field could be general wrapper of the field itself. Now create an event handler for your combo: $(".

ValueCount"). Change(function(){ var count = $(this).val(), $fields = $(this). Closest("fieldgroup").

Find(". Field"); if ($fields.size() > count) //remove fields $fields. Slice(count).remove(); else if ($fields.size() InsertAfter($fields.last()); } }); On the server side you will have all the values in single array $_REQUEST'dynamicfield'; Do whatever validation you like on it.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions