PDA

View Full Version : Form PHP/Javascript tabbed pane



chidanandmba
Apr 21st, 2007, 12:48 PM
Hi to all,

I am new to javascript, I have the following code(below), which has two tabbed panes and like wise have no problem in displaying the contents, But when we come across the validation part, I get an error saying :


document.forms... is null or not an object..

(Help appreciated)
Thanks in advance for your spare time and expertise



<?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 the order id records with attachments
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