You need to sign in to do that
Don't have an account?
Reg: Controls at run time
Hi,
Good Morning.
can any one help me to solve the following.........
I have an object student__c. It has only one field name.i would like to add the records into object using VF page.
Initiallay, In VF page I have Add button,Save button & a text box. When i click on add button i need to display one more textbox. Like this i can add any number of textboxes. But when i entered data into these textboxes and clicked on save. I would like to add all the names into object in the form of records. That means, each name will be added into object as a record.
Can any one help me.
Thanks & Regards:
sri
<apex:page controller="ControllerV1">
<body>
<form>
<table id="TableId">
<thead>
<tr>
<th scope="col" class="num"></th>
<th scope="col" class="fname">Name</th>
</tr>
</thead>
<tbody id="tablebody">
<tr>
<td class="num">1.</td>
<td><input type="text" name="" value="" id="name1"/></td>
</tr>
</tbody>
<tfoot>
<tr>
<td><input type="Button" value="Save" onclick="Validate();"/></td>
<td colspan="2"> <a onclick="InsertRow();">Add More 1 Records</a> </td>
</tr>
</tfoot>
</table>
<script>
var AllName = '';
function addRow(num)
{
if(document.all)
{
var tbody1 = document.getElementById('tablebody');
var row = document.createElement("TR");
var td1 = document.createElement("TD");
td1.setAttribute("className","num");
td1.innerHTML = num + '.' ;
var td2 = document.createElement("TD");
var SpanTd2 = document.createElement("Span");
var aTextBoxSpanTd2 = document.createElement('input');
aTextBoxSpanTd2.type = "text";
aTextBoxSpanTd2.id = "name" + num ;
SpanTd2.appendChild(aTextBoxSpanTd2);
td2.appendChild(SpanTd2);
row.appendChild(td1);
row.appendChild(td2);
tbody1.appendChild(row);
}
else
{
var tbody1 = document.getElementById('tablebody');
var row = document.createElement("TR");
var td1 = document.createElement("TD");
td1.setAttribute("class","num");
td1.innerHTML = num + '.' ;
var td2 = document.createElement("TD");
var SpanTd2 = document.createElement("Span");
var aTextBoxSpanTd2 = document.createElement('input');
aTextBoxSpanTd2.type = "text";
aTextBoxSpanTd2.id = "name" + num ;
SpanTd2.appendChild(aTextBoxSpanTd2);
td2.appendChild(SpanTd2);
row.appendChild(td1);
row.appendChild(td2);
tbody1.appendChild(row);
}
}
function InsertRow()
{
var table = document.getElementById("TableId");
var strTb = '', rowCount = table.rows.length;
var NewId = rowCount-1;
for(i = NewId ; i < NewId + 1 ; ++i)
{
addRow(i);
}
}
function Validate()
{
var table = document.getElementById("TableId");
var rowCount = table.rows.length;
var MyTeam = new Array(rowCount);
for(i = 1 ; i <= rowCount-2 ; i++)
{
var Name = "name" + i;
var NameValue = document.getElementById(Name).value;
if(NameValue == '')
{
alert("Name is required in S.no" + " " + i);
}
else
{
if(i == 1)
{
AllName = NameValue;
}
else
{
AllName = AllName + ';' + NameValue;
}
}
}
alert(AllName); // Pass All name into the controller and separate this string value by ; and insert all the record.
}
</script>
</form>
</body>
</apex:page>
All Answers
<apex:page controller="ControllerV1">
<body>
<form>
<table id="TableId">
<thead>
<tr>
<th scope="col" class="num"></th>
<th scope="col" class="fname">Name</th>
</tr>
</thead>
<tbody id="tablebody">
<tr>
<td class="num">1.</td>
<td><input type="text" name="" value="" id="name1"/></td>
</tr>
</tbody>
<tfoot>
<tr>
<td><input type="Button" value="Save" onclick="Validate();"/></td>
<td colspan="2"> <a onclick="InsertRow();">Add More 1 Records</a> </td>
</tr>
</tfoot>
</table>
<script>
var AllName = '';
function addRow(num)
{
if(document.all)
{
var tbody1 = document.getElementById('tablebody');
var row = document.createElement("TR");
var td1 = document.createElement("TD");
td1.setAttribute("className","num");
td1.innerHTML = num + '.' ;
var td2 = document.createElement("TD");
var SpanTd2 = document.createElement("Span");
var aTextBoxSpanTd2 = document.createElement('input');
aTextBoxSpanTd2.type = "text";
aTextBoxSpanTd2.id = "name" + num ;
SpanTd2.appendChild(aTextBoxSpanTd2);
td2.appendChild(SpanTd2);
row.appendChild(td1);
row.appendChild(td2);
tbody1.appendChild(row);
}
else
{
var tbody1 = document.getElementById('tablebody');
var row = document.createElement("TR");
var td1 = document.createElement("TD");
td1.setAttribute("class","num");
td1.innerHTML = num + '.' ;
var td2 = document.createElement("TD");
var SpanTd2 = document.createElement("Span");
var aTextBoxSpanTd2 = document.createElement('input');
aTextBoxSpanTd2.type = "text";
aTextBoxSpanTd2.id = "name" + num ;
SpanTd2.appendChild(aTextBoxSpanTd2);
td2.appendChild(SpanTd2);
row.appendChild(td1);
row.appendChild(td2);
tbody1.appendChild(row);
}
}
function InsertRow()
{
var table = document.getElementById("TableId");
var strTb = '', rowCount = table.rows.length;
var NewId = rowCount-1;
for(i = NewId ; i < NewId + 1 ; ++i)
{
addRow(i);
}
}
function Validate()
{
var table = document.getElementById("TableId");
var rowCount = table.rows.length;
var MyTeam = new Array(rowCount);
for(i = 1 ; i <= rowCount-2 ; i++)
{
var Name = "name" + i;
var NameValue = document.getElementById(Name).value;
if(NameValue == '')
{
alert("Name is required in S.no" + " " + i);
}
else
{
if(i == 1)
{
AllName = NameValue;
}
else
{
AllName = AllName + ';' + NameValue;
}
}
}
alert(AllName); // Pass All name into the controller and separate this string value by ; and insert all the record.
}
</script>
</form>
</body>
</apex:page>
Sorry, I am very new to Salesforce Apex programming.
I could not get AllNames.
please send the controller code also.
Thanks & Regards:
pradeep
We have same requirement can u post Controller for that page
ThanX
Hari@RockZ