Form in PHP/Javascript Tabbed Pane
I have a form (with a input field and submit) in Facilities Tab of my Tabbed Pane. I php searches for the number of existing orders and then shows up those many number of forms.When I click submit, it has to check for, whether the attachement is browsed and selected. In case there is no attachment, it must focus back to the Browse field. with an alert statement
But, when we click Submit button, it says
document.all.t2Contents.forms is null or not object..
Am I wrong some where?
I have been trying with document.getElementsById and getElementsBy Name. But the problem still exist, since I generate multiple forms based on the database, the form name and element name keep on changing, its creating a problem..
If any body knows the solution, please let me know..
(Code below). Appreciate your help. Thanks in advance for your time and expertise.
Chidu
chidanandmba@gmail.com
<?php
ob_start();
session_start();
require_once ("checksession.php");
require_once ("../config.php");
require_once ("../classes/database.php");
$db = new database();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>MGH ::: <?php echo $type;?></title>
<link href="logo.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/JavaScript">
//a public function that the container uses to pass in values for the labels
function public_Labels(label1, label2){
t1.innerText = label1;
t2.innerText = label2;
}
//a public function that the container uses to pass in values for the card containers
function public_Contents(contents1, contents2){
t1Contents.innerHTML = contents1;
t2Contents.innerHTML = contents2;
init();
}
//sets the default display to tab 1
function init(){
tabContents.innerHTML = t1Contents.innerHTML;
}
//this is the tab switching function
var currentTab;
var tabBase;
var firstFlag = true;
function changeTabs(){
if(firstFlag == true){
currentTab = t1;
tabBase = t1base;
firstFlag = false;
}
if(window.event.srcElement.className == "tab"){
currentTab.className = "tab";
tabBase.style.backgroundColor = "white";
currentTab = window.event.srcElement;
tabBaseID = currentTab.id + "base";
tabContentID = currentTab.id + "Contents";
tabBase = document.all(tabBaseID);
tabContent = document.all(tabContentID);
currentTab.className = "selTab";
tabBase.style.backgroundColor = "";
tabContents.innerHTML = tabContent.innerHTML;
}
}
function getAttachment(form_name)
{
if(document.all.t2Contents.forms[form_name].elements["attachment"].value=='')
{
alert("Enter Attachment");
document.all.t2Contents.forms[form_name].elements["attachment"].focus();
return false;
}
return true;
}
</script>
</head>
<BODY onclick="changeTabs()" onload="init()">
<div align="center">
<br>
<div align="center">
<TABLE BGCOLOR=#C0C0C0 width="800" CELLPADDING=0 CELLSPACING=0>
<TR>
<TD ID=t1 CLASS=selTab HEIGHT=25 WIDTH="15%">Items</TD>
<TD ID=t2 CLASS=tab HEIGHT=25 WIDTH="15%">Facilities</TD>
<TD ID=t3 CLASS=noTab STYLE="background-color:white"></TD>
</TR>
<TR>
<TD ID=t1base STYLE="height:2; border-left:solid thin white"></TD>
<TD ID=t2base STYLE="height:2; background-color:white"></TD>
<TD ID=t3base STYLE="height:2; background-color:white"></TD>
</TR>
<TR>
<TD HEIGHT="*" COLSPAN=3 ID=tabContents
STYLE="border-left:solid thin gray;
border-bottom:solid thin gray;
border-right:solid thin gray">sample contents</TD>
</TR>
</TABLE>
</div>
<br>
<!-- ITEMS TAB -->
<DIV CLASS=conts ID=t1Contents>
<table width="800" border="1" cellpadding="1" cellspacing="0" bordercolor="#CCCCCC">
<tr align="center" valign="middle">
<td width="30%" class="boldtext">Item</td>
<td width="10%" class="boldtext">Code</td>
</tr>
</table>
</DIV>
<!-- FACILITIES TAB -->
<DIV CLASS=conts ID=t2Contents>
<table width="800" border="1" cellpadding="1" cellspacing="0" bordercolor="#cccccc">
<?php
$facilitydisplay = $order->getDisplayfacility($orderid); //search for all the records w.r.t order id
$faccount=-1;
foreach($facilitydisplay as $facidisply)
{
$faccount++;
$faciattachments= $order->getFacility1($facidisply['facility_code'],$orderid); // search for all attachements for the order id
echo "<tr valign=\"top\" class=\"e".($faccount & 1)."\">";
foreach($faciattachments as $attachments)
{
$filename = $attachments['file_name'];
$attachment = $attachments['attachment'];
?>
<td width="55%" align="left" class="text"> Attachments: </td>
<td valign="top" align="right">
<?php $attachment_form_name = 'attachment'.$faccount; ?>
<form name="<?php echo $attachment_form_name; ?>" method="post" action="" enctype="multipart/form-data" onSubmit="return getAttachment('<?php echo $attachment_form_name; ?>');">
<input name="attachment" type="file" class="text" size="35">
<input name="Submit" type="submit" class="buttonstyle" value="Attach">
</form>
</td>
</tr>
<?php
}
}
?>
</table>
</DIV>
</div>
</body>
</html>
With Regards
Chidanand. G.B

