admiralq
07-05-2012, 03:26 AM
I need to pass javascript variables "a1" to "a35" to respective "hidden" form inputs.
I have up to 35 students in a class. Rather than have the page reload (and deal with potential slow downs each time during class) I decided to write a program which allows me to edit each student's variable by +1 or -1 as many times as I like ... and THEN submit the form for ONE php database update upon completion. I know how to do everything except pass the javascript variables by form to the form handler.
I tried the following:
$count = 0;
while ($count <= $num_rows){
print "<input type=\"hidden\" name=\"stu".$count."\" value=\"a".$count."\"><br>";
$count++;
}
$num_rows = the number of students in the class (roughly 35);
I knew the coding wouldn't work, but it was what my previous experience with forms led me to believe was a good start.
The actual javascript variable values are set by the following code:
$count = 0;
while ($count <= $num_rows){
print "<script type=\"text/javascript\">";
print "var a$count=0;";
print "function increase$count()";
print "{a$count++;";
print "document.getElementById('boldstuff$count').innerHTML= +a$count;}";
print "</script>";
$count++;
}
... and
$count = 0;
$query1 = "SELECT * FROM chs_students WHERE spanish = '$period' and uname != 'admiralq' ORDER BY lname, fname";
$result1= mysql_query($query1) or die("Could not perform query: ".mysql_error());
while ($row1 = mysql_fetch_array($result1)){
$count++;
print $count.". <span onclick=\"increase".$count."();\">".$row1['lname'].", ".$row1['fname']."<b id=\"boldstuff".$count."\">0</b></span> ".$a1." <span onclick=\"decrease".$count."();\">(minus)</span><br>\n";
}
God, this is a mess, isn't it? Thanks.
I have up to 35 students in a class. Rather than have the page reload (and deal with potential slow downs each time during class) I decided to write a program which allows me to edit each student's variable by +1 or -1 as many times as I like ... and THEN submit the form for ONE php database update upon completion. I know how to do everything except pass the javascript variables by form to the form handler.
I tried the following:
$count = 0;
while ($count <= $num_rows){
print "<input type=\"hidden\" name=\"stu".$count."\" value=\"a".$count."\"><br>";
$count++;
}
$num_rows = the number of students in the class (roughly 35);
I knew the coding wouldn't work, but it was what my previous experience with forms led me to believe was a good start.
The actual javascript variable values are set by the following code:
$count = 0;
while ($count <= $num_rows){
print "<script type=\"text/javascript\">";
print "var a$count=0;";
print "function increase$count()";
print "{a$count++;";
print "document.getElementById('boldstuff$count').innerHTML= +a$count;}";
print "</script>";
$count++;
}
... and
$count = 0;
$query1 = "SELECT * FROM chs_students WHERE spanish = '$period' and uname != 'admiralq' ORDER BY lname, fname";
$result1= mysql_query($query1) or die("Could not perform query: ".mysql_error());
while ($row1 = mysql_fetch_array($result1)){
$count++;
print $count.". <span onclick=\"increase".$count."();\">".$row1['lname'].", ".$row1['fname']."<b id=\"boldstuff".$count."\">0</b></span> ".$a1." <span onclick=\"decrease".$count."();\">(minus)</span><br>\n";
}
God, this is a mess, isn't it? Thanks.