Mat
08-12-2003, 12:53 AM
I've spent the last few days trying to figure out how to dynamically add input elements to my website, and then on how to receive and iterate through the posted form elements, so that I can process them.
But I seem to have done something wrong along the way.
I have my form, which starts right under my body tag, and closes right before the close body tag (this is to make sure I don't forget anything).
My page adds my input elements (specifically textareas) to the page within the the form tags.
Unfortunately, when I through the received fields on the receiving page, none of my dynamic elements show up (though all the static ones do). If this will help, here's the code I'm using:
On the sending page:
...
<body ...>
<form id="create_new" action="new_evaluate.asp" method="POST">
...then a number of form elements
<input type=button onclick="addGoal();" id="newgoal" name="newgoal" value="Add New Goal" class="mediumsize">
...
var x = 0;
var y = 0;
button_num=0;
obj_num=0;
rec_num=0;
function button_clicked(element,text){
codeobj="<table><tr><td>Objective</td><td></td><td>Mid-Term Evaluation</td><td></td><td>Final Evaluation</td></tr><tr><td width=30%><textarea style='width: 100%;' cols=1 rows=4 id=text1"+obj_num+" name text1"+obj_num+"></textarea></td><td width=5%></td><td width=30%><textarea style='width: 100%;' cols=1 rows=4 id=text2"+obj_num+"></textarea></td><td width=5%></td><td><textarea style='width: 100%;' cols=1 rows=4 id=text3"+obj_num+"></textarea></td></tr></table>";
document.getElementById('innergoaldiv'+text).innerHTML+=codeobj;
obj_num++;
}
function addGoal(){
code="<div id='innergoaldiv"+button_num+"'><textarea cols=10 rows=4 name=goal"+button_num+" id="+button_num+" style='width: 98%;'></textarea><br><input type=button value='Add New Objective' onclick=\"button_clicked(document.getElementById('"+button_num+"'),'"+button_num+"')\"><br></div><hr>";
document.getElementById('goaldiv').innerHTML+=code;
button_num++;
document.getElementById("numgoals").setAttribute("value", button_num);
}
function addRec(){
coderec="<table width=98%><tr class='mediumsize'><td align=center>Recommendation</td><td></td><td align=center>Mid-Term Evaluation</td><td></td><td align=center>Final Evaluation</td></tr><tr><td width=30%><textarea style='width: 100%;' cols=1 rows=4 id=rec1"+obj_num+"></textarea></td><td width=5%></td><td width=30%><textarea style='width: 100%;' cols=10 rows=4 id=rec2"+obj_num+"></textarea></td><td width=5%></td><td><textarea style='width: 100%;' cols=1 rows=4 id=rec3"+obj_num+"></textarea></td></tr></table><hr>";
document.getElementById('recdiv').innerHTML+=coderec;
rec_num++;
}
(I have taken out all the non-essential stuff I could find - hope its not too much junk)
...
</form>
...
On the receiving page:
...
'
' Build HTML body
str = ""
For Each fld in Request.Form
str = str & (fld & " = '" & Trim(Request.Form(fld)) & "'<br>" & vbCRLF)
Next
If Len(str) > 0 Then
Response.Write "<p>" & Left(str, Len(str) - 6) & "</p>" & vbCrLf
Else
Response.Write "<p> </p>" & vbCrLf
End If
...
This is actually taken directly off other help I got on the ASP page, and successfully returns everything else.
Can anybody see what I'm doing wrong?
Thanks,
Mat
But I seem to have done something wrong along the way.
I have my form, which starts right under my body tag, and closes right before the close body tag (this is to make sure I don't forget anything).
My page adds my input elements (specifically textareas) to the page within the the form tags.
Unfortunately, when I through the received fields on the receiving page, none of my dynamic elements show up (though all the static ones do). If this will help, here's the code I'm using:
On the sending page:
...
<body ...>
<form id="create_new" action="new_evaluate.asp" method="POST">
...then a number of form elements
<input type=button onclick="addGoal();" id="newgoal" name="newgoal" value="Add New Goal" class="mediumsize">
...
var x = 0;
var y = 0;
button_num=0;
obj_num=0;
rec_num=0;
function button_clicked(element,text){
codeobj="<table><tr><td>Objective</td><td></td><td>Mid-Term Evaluation</td><td></td><td>Final Evaluation</td></tr><tr><td width=30%><textarea style='width: 100%;' cols=1 rows=4 id=text1"+obj_num+" name text1"+obj_num+"></textarea></td><td width=5%></td><td width=30%><textarea style='width: 100%;' cols=1 rows=4 id=text2"+obj_num+"></textarea></td><td width=5%></td><td><textarea style='width: 100%;' cols=1 rows=4 id=text3"+obj_num+"></textarea></td></tr></table>";
document.getElementById('innergoaldiv'+text).innerHTML+=codeobj;
obj_num++;
}
function addGoal(){
code="<div id='innergoaldiv"+button_num+"'><textarea cols=10 rows=4 name=goal"+button_num+" id="+button_num+" style='width: 98%;'></textarea><br><input type=button value='Add New Objective' onclick=\"button_clicked(document.getElementById('"+button_num+"'),'"+button_num+"')\"><br></div><hr>";
document.getElementById('goaldiv').innerHTML+=code;
button_num++;
document.getElementById("numgoals").setAttribute("value", button_num);
}
function addRec(){
coderec="<table width=98%><tr class='mediumsize'><td align=center>Recommendation</td><td></td><td align=center>Mid-Term Evaluation</td><td></td><td align=center>Final Evaluation</td></tr><tr><td width=30%><textarea style='width: 100%;' cols=1 rows=4 id=rec1"+obj_num+"></textarea></td><td width=5%></td><td width=30%><textarea style='width: 100%;' cols=10 rows=4 id=rec2"+obj_num+"></textarea></td><td width=5%></td><td><textarea style='width: 100%;' cols=1 rows=4 id=rec3"+obj_num+"></textarea></td></tr></table><hr>";
document.getElementById('recdiv').innerHTML+=coderec;
rec_num++;
}
(I have taken out all the non-essential stuff I could find - hope its not too much junk)
...
</form>
...
On the receiving page:
...
'
' Build HTML body
str = ""
For Each fld in Request.Form
str = str & (fld & " = '" & Trim(Request.Form(fld)) & "'<br>" & vbCRLF)
Next
If Len(str) > 0 Then
Response.Write "<p>" & Left(str, Len(str) - 6) & "</p>" & vbCrLf
Else
Response.Write "<p> </p>" & vbCrLf
End If
...
This is actually taken directly off other help I got on the ASP page, and successfully returns everything else.
Can anybody see what I'm doing wrong?
Thanks,
Mat