Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Variables between PHP and JavaScript (URGENT)

Status
Not open for further replies.

najjar

Programmer
Jun 5, 2002
11
US
<!--
Hi,
This is my code
I'm basiclly trying to Pass Values (variables) between PHP
and JavaScript using The Variable [[$num_Courses]]
I'm trying to pass the num_Courses from PHP to JavaScript
so when I click on checkall Function it checks all the
checkboxs I want

I'm using nested loops to create a table of:
Student Names | Test1 | Test2 | Test3 ......
. . . .
. . . .
. . . .

(((I'm gonna put it between 2 lines so you can know it)))
Depends on the entries I have.
................Help Me PLease..............

-->

<?php require (&quot;sql.php&quot;); ?>

<HTML>

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! -->

<!-- Begin
function checkAll($num_Courses) {
for (var j = 1; j <= $num_Courses; j++) {
box = eval(&quot;document.checkboxform.C&quot; + j);
if (box.checked == false) box.checked = true;
}
}

function uncheckAll($num_Courses) {
for (var j = 1; j <= $num_Courses; j++) {
box = eval(&quot;document.checkboxform.C&quot; + j);
if (box.checked == true) box.checked = false;
}
}

function switchAll($num_Courses) {
for (var j = 1; j <= $num_Courses; j++) {
box = eval(&quot;document.checkboxform.C&quot; + j);
box.checked = !box.checked;
}
}

// End -->
</script>

<BODY background=&quot;bkgnd5.jpg&quot;>
<?php
// Translate Course_Name into Course_ID
// Search for Course_ID in Test_Dates Table
// Display fields 'Description' and 'Test_Dates' from Test_Dates Table w/checkboxes next to them.
// Once checkbox(es) are clicked, and submits form, UPDATE everything in the database (into table Test_Taken.


echo(&quot;<FORM METHOD=POST ACTION='inserttestdates.php'> <INPUT TYPE=HIDDEN NAME=Student_ID VALUE=$Course_ID>&quot;);

$SQL = &quot;SELECT * FROM Student_Access WHERE Course_ID = '$Course_ID' Order by Student_ID&quot;;
$num_Courses = numSQL($SQL);
$count = 0;

while ($count < $num_Courses) {
$Student_ID_Array[$count] = rmSQL($SQL, $count, 'Student_ID');
$count = $count + 1;
}

$SQLSt = &quot;SELECT * FROM feeds_student_info, Student_Access WHERE feeds_student_info.Student_ID = Student_Access.Student_ID and Course_ID = '$Course_ID'&quot;;
$numStudents = numSQL($SQLSt);
$count = 0;

while ($count < $num_Courses) {
$L_Name[$count] = rmSQL($SQLSt, $count, 'L_Name');
$F_Name[$count] = rmSQL($SQLSt, $count, 'F_Name');
$count++;
}

$SQL = &quot;SELECT * FROM Test_Dates WHERE Course_ID = '$Course_ID'&quot;;
$num_Tests = numSQL($SQL);
$count = 0;

while ($count < $num_Tests) {
$DescriptionArray[$count] = rmSQL($SQL, $count, 'Description');
$Test_DatesArray[$count] = rmSQL($SQL, $count, 'Test_Dates');
$Test_IDArray[$count] = rmSQL($SQL, $count, 'Test_ID');
$count = $count + 1;
}

$SQL2 = &quot;SELECT Course_Name FROM Course_Info WHERE Course_ID = '$Course_ID'&quot;;
$num_Records = numSQL($SQL2);
$count = 0;

while ($count < $num_Records)
{
$CourseNameArray[$count] = rSQL($SQL2, $count, 'Course_Name');
$count = $count + 1;
}

If ($num_Tests != &quot;0&quot;)
{
echo(&quot;<INPUT TYPE=HIDDEN NAME=Course_ID VALUE=$Course_ID>&quot;);
echo(&quot;<INPUT TYPE=HIDDEN NAME=St_ID VALUE=$St_ID>&quot;);
echo(&quot;<INPUT TYPE=HIDDEN NAME=num_Tests VALUE=$num_Tests>&quot;);
echo(&quot;<INPUT TYPE=HIDDEN NAME=num_Courses VALUE=$num_Courses>&quot;);
$SQL222 = &quot;SELECT * FROM Test_Taken WHERE Course_ID = '$Course_ID' AND Test_ID = '$Test_IDArray[0]' AND Student_ID = '$Student_ID'&quot;;
$num = numSQL($SQL222);

for($c = 0; $c < $num_Tests; $c++)
{
if ($num == 0)
{
$SQL = &quot;INSERT INTO Test_Taken (Student_ID, Course_ID, Test_Taken, Test_Passed, Test_ID, File_Link) VALUES('$Student_ID', '$Course_ID', '$Test_Dates_Array[$c]', 'off', $Test_IDArray[$c], 'file.path')&quot;;
wSQL($SQL);
}
}
echo(&quot;<Center><Table Border = 4>&quot;);
$isChecked = &quot;Checked&quot;;
$isUnChecked = &quot;UnChecked&quot;;
for($c = 0; $c < $num_Tests; $c++)
{
echo(&quot;<TD bgcolor = 'aabbcc'><B>$DescriptionArray[$c] [ $Test_DatesArray[$c] ]</B></TD><TD bgcolor = 'black'></TD>&quot;);
echo(&quot;<TD><INPUT TYPE=checkbox NAME='Select_All' VALUE='$Test_IDArray[$c]' onClick=checkAll($num_Courses)> Check All </TD>&quot;);
echo(&quot;<TD bgcolor = 'black'></TD><TD><INPUT TYPE=checkbox NAME='Unselect_All' VALUE='$Test_IDArray[$c]' onClick=uncheckAll($num_Courses)> Uncheck All </TD><TD bgcolor = 'black'></TD></TR><TR><TD></TD></TR>&quot;);
}
echo(&quot;</TR>&quot;);
echo(&quot;</Table><BR><BR>&quot;);
echo(&quot;<Center><Table Border = 3>&quot;);
echo(&quot;<TR><TD bgcolor = 'aabbcc'></TD><TD colspan=4><Center><FONT SIZE=+1>Tests Available for $CourseNameArray[0]</FONT><Center></TD></TR>&quot;);
echo(&quot;<TR><TD>Student Name</TD>&quot;);
for($c = 0; $c < $num_Tests; $c++)
{
echo(&quot;<TD bgcolor='aabbcc'></TD>&quot;);
}

$count = 0;
/**********These are the loops that**************/
/**********Generates the table**************/


while ($count < $num_Courses)
{
echo(&quot;<tr><td><input type=checkbox Name=St_ID Value=$Student_ID_Array[$count]>$L_Name[$count], $F_Name[$count]</td>&quot;);
for($c = 0; $c < $num_Tests; $c++)
{
echo(&quot;<TD><CENTER><INPUT TYPE=checkbox NAME='Test_IDArray[]' VALUE='$Test_IDArray[$c]'> $DescriptionArray[$c] [ $Test_DatesArray[$c] ]</CENTER></TD>&quot;);
}
$count = $count + 1;
}
/***************************************/


echo(&quot;</TABLE><br>&quot;);
echo(&quot;<CENTER><INPUT TYPE=SUBMIT NAME=SUBMIT9 VALUE='Update Test Status'></CENTER>&quot;);

echo(&quot;</FORM>&quot;);
}
Else
{
echo(&quot;<BR><CENTER><FONT SIZE=+1>There currently are no tests assigned for this course. Please go to the 'Test Manager' module to assign tests for this course.</FONT></CENTER><BR>&quot;);
echo(&quot;<BR><CENTER><INPUT TYPE='button' VALUE='< Back' onClick='javascript:history.go(-1)'\n></CENTER>&quot;);
}

?>

</BODY>
</HTML>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top