0

I have created a form with dynamic field. but i m getting confused that how should i post data into database. because there would be different field according to different users. here is the basic code with one dynamic field

function add2(type) {
     var element = document.createElement("textArea");
     var label=prompt("Enter the name for lable","label");
     document.getElementById('raj').innerHTML=document.getElementById('raj').innerHTML+label;
     element.setAttribute("type", type);

     element.setAttribute("name", type);
     var col=prompt('Enter the no of columns');
     element.setAttribute("cols",col);
     var row=prompt('Enter the no of rows');
     element.setAttribute("rows",row);

     var rohit = document.getElementById("raj");
    rohit.appendChild(element);
    document.getElementById('raj').innerHTML=document.getElementById('raj').innerHTML+"<br/>";

}

here is the calling of this function.

<input type="button" value="Text Area" onclick="add2('textarea')"><br/>
</div>

<div id="content" style="height:200px;width:400px;float:left;">
<form action="#" method="post">
<span id="raj">&nbsp</span>
<input type="submit" value="submit"></div>

help me guys what should i do to store the dynamic elements into database and what fields should i put into database

1 Answer 1

0

Store the field values separated in one hiddenfield, and get them from the serves side.

<input id="values" type="hidden" value="value1,value2,value3">

on submit:

var Valuearray = values.value.Split(',');
2
  • I dont know, how many value will be there, so how can i decide Jul 11, 2012 at 13:31
  • When you added a control dynamically, you must handle the new control's valuechange event. In the eventhandler you will iterate your controls on the form, and save the identity and value pair in the hiddenfield. When you submit the form, you will check the value of hiddenfield, and count the controls, and their values, and you will know everything.
    – speti43
    Jul 11, 2012 at 13:38

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.