Hello Everyone,
I have a form (it is for a web based poll) it collects 4 pieces of information:
1) the poll question
2) the amoutn of choices
3) the start date of poll
4) the end date for poll
Now when this form is submitted(same script $php_self) it takes the amount of choices entered and
I run a for loop to get the amount of text-boxes I need in the new form, they are dynamically created using names choice1, choice2
and so on depending on the amount entered in the form before.
That is not the problem, that part is working great.
The problem comes in when I want to run a javascript script to get the values of the text fields, I use the following code:
elseif (isset($_POST['submit1']))
{
$question = $_POST['question'];
$totalchoices= $_POST['totalchoices'];
$startdate = $_POST['startdate'];
$enddate = $_POST['enddate'];
$php_self = $_SERVER['PHP_SELF'];
$steptwodata = <<<endofsteptwodata
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Web Poll Generator</title>
<script language="javascript" type="text/javascript">
function checkForm(form)
{
var howMany = form.elements.length;
var i = 0;
for (count = 0; count < howMany; count++)
{
document.write(form.elements[count].value +"<br />");
}
return false;
}
</script>
</head>
<body>
<form name="formgenerator2" action="$php_self" method="post" onSubmit="return checkForm(this);">
<div align="center">
<table border="1" cellpadding="5" cellspacing="0" width="600" bordercolor="#CCCCCC" bgcolor="#FFFF00">
<tr>
<td>
<div align="center">
<table border="1" cellpadding="5" cellspacing="0" width="100%" bordercolor="#DDDDDD" bgcolor="#FFFFFF" id="table2" style="font-family: Tahoma; font-size: 12px; color: #000000">
<tr>
<td colspan="2"><p align="center"><font color="#008000"><b>Web Poll Generator</b></font></td>
</tr>
endofsteptwodata;
for ($datacount = 0,$choicecount = 1; $datacount < $totalchoices; $datacount++,$choicecount++)
{
$steptwodata .= <<<endofsteptwodata
<tr>
<td width="126" align="left">Choice $choicecount:</td>
<td align="left"><input type="text" name="choice$choicecount" size="30" tabindex="$choicecount" style="font-family: Tahoma; font-size: 12px; color: #800000"></td>
</tr>
endofsteptwodata;
}
$steptwodata .= <<<endofsteptwodata
<tr>
<input type="hidden" name="question" value="$question" />
<input type="hidden" name="totalchoices" value="$totalchoices" />
<input type="hidden" name="startdate" value="$startdate" />
<input type="hidden" name="enddate" value="$enddate" />
<td colspan="2" align="center"><input type="submit" value="Generate Poll" name="submit2" tabindex="99" style="font-family: Tahoma; font-size: 12px; color: #008000"></td>
</tr>
<tr>
</table>
</div>
</td>
</tr>
</table>
</div>
</form>
endofsteptwodata;
print $steptwodata;
The problem is that for some reason it ONLY recognizes the very first text input and not the others.
All I get on the output is the value of the first text box not the others.
is there something I am doing wrong?
Is there anything in PHP that I could do to accomplish the same thing?
Any and all help will be greatly appreciated.
Thank you in advance
Leo Zayas