The second task was also quite simple as you may be wondering. We needed to have a box in which student USN and names appear and another box into which we needed to transfer these students. Google helped us out again.
We have the following php script...
------------------------------------------------------
<html>
<script language="JavaScript"><!--
function populateForm() {
for (var Current=0;Current < document.formName.selectName1.options.length;Current++) {
if (document.formName.selectName1.options[Current].selected) {
var defaultSelected = true, selected = true;
var optionName = new Option(document.formName.selectName1.options[Current].value, document.formName.selectName1.options[Current].text, defaultSelected, selected)
if (replacedfirst)
var length = document.formName.selectName2.length;
else
var length = 0;
document.formName.selectName2.options[length] = optionName;
replacedfirst = true;
}
}
}
var replacedfirst = false;
</script>
<form name="formName" onSubmit="return false;">
<select name="selectName1" multiple size="3">
</select>
<input type="button" value="Enter" onClick="populateForm()">
<select name="selectName2" multiple size="3">
<option value="">
</select>
</form>
</html>
----------------------------------------------
The following was the output:
As you may see the interface is quite simple and elegant. A faculty is required to make a list of students who are absent and submit it to the database. Where php comes in this you may be wondering. It comes when you query the database to populate the student list in the first box. I will soon post the code for that too.
We have the following php script...
------------------------------------------------------
<html>
<script language="JavaScript"><!--
function populateForm() {
for (var Current=0;Current < document.formName.selectName1.options.length;Current++) {
if (document.formName.selectName1.options[Current].selected) {
var defaultSelected = true, selected = true;
var optionName = new Option(document.formName.selectName1.options[Current].value, document.formName.selectName1.options[Current].text, defaultSelected, selected)
if (replacedfirst)
var length = document.formName.selectName2.length;
else
var length = 0;
document.formName.selectName2.options[length] = optionName;
replacedfirst = true;
}
}
}
var replacedfirst = false;
</script>
<form name="formName" onSubmit="return false;">
<select name="selectName1" multiple size="3">
</select>
<input type="button" value="Enter" onClick="populateForm()">
<select name="selectName2" multiple size="3">
<option value="">
</select>
</form>
</html>
----------------------------------------------
The following was the output:
As you may see the interface is quite simple and elegant. A faculty is required to make a list of students who are absent and submit it to the database. Where php comes in this you may be wondering. It comes when you query the database to populate the student list in the first box. I will soon post the code for that too.
No comments:
Post a Comment