Keep the following in mind:
- Your 2 calls to the openWindow() function will create 2 identical forms along with the javascript blocks below it.
- Since you have hardcoded the id of the form to be 'TheForm', it is illegal, since the element id should be unique in the DOM. Hence document.getElementById('TheForm') is ambiguous
- You are better off using JavaScript to open URLs e.g. with window.open rather than the PHP function calls
Example:
Since the details of the requirements are unknown, it is difficult to suggest the correct solution, even if you get your initial code working. I would not recommend trying to open multiple new tabs programmatically. One reason is usability/user experience. Another reason is that there is no standard supported method to get this working on a variety of browsers and browser settings. There is css3 recommendation for opening in a new tab.
2 solutions you might want to consider:
a) Opening multiple pages as popups
b) Opening a single page with multiple records for each student
Depending on what you are after, you need to decide. For most cases, option be will be suitable.
Sample of option (a):
test.php
<html>
<head>
</head>
<body>
<form id='studentform' method='post' action='studentDetails.php' target="_blank">
<input type='hidden' name='name' id="name" value="" />
<input type='hidden' name='id' id="id" value="" />
</form>
<script type='text/javascript'>
function openWindows(){
window.open("http://localhost/test/studentDetails/studentDetails.php?name=john&id=1", "", "width=600, height=300");
window.open("http://localhost/test/studentDetails/studentDetails.php?name=mary&id=2", "", "width=600, height=300");
}
openWindows();
</script>
</body>
</html>
studentDetails.php
<?php
function getParam($name,$method){
if($method=="POST")
return isset($_POST[$name])?$_POST[$name]:"";
else
return isset($_GET[$name])?$_GET[$name]:"";
}
$name = getParam("name", "GET");
$id = getParam("id", "GET");
if($name && $id)
echo("name = $name and Id = $id");
else
echo("Invalid student info");
?>