Javascript error states form name is not defined although it is

Sorry about the state of the code below I'm using dreamweaver and its crap! Anyway about half
way down the script there is a form named form2!

That form includes an object that displays a list of images and when I select one of the images in the list a preview appears. It worked until embedding it within a more complicated page and now I get a javascript error stating 'Form2' has not been defined.

That error comes from the script about 19 lines down. Any ideas why this is happening?
<?
session_start();
if(!session_is_registered(myusername)){
header("location:index.php");
}
?>
<?php include 'phptxt/header.inc'; ?>
<head>
<title>iFolio</title>
	<?php include 'phptxt/meta.inc'; ?>
	<link href="css/main.css" rel="stylesheet" type="text/css">
	<link href="css/user.css" rel="stylesheet" type="text/css">
<script language="JavaScript">
function change(html){
  descriptions.innerHTML=html
}
function pre() {
form2.preview.src = 'gallery/thumbnails/image'+form2.choiceimage.options[form2.choiceimage.selectedIndex].value+'.jpg';
}
</script>
</head>
 
<body>
 
<div id="Table_01">
<table id="Table_01" width="830" height="926" border="0" cellpadding="0" cellspacing="0">
		
	<tr><!-- Header START -->
	  <td width="830" height="153" colspan="3">
  	    <div id="LogID">
  	      <div align="center">You are logged in<br/>
  	        <img src="images/Me n Suit.jpg" width="75" height="82"><br/>
  	        <a href="/ifolio/loggedout.php">Log Out</a>  	      </div>
  	    </div>
	    <?php include 'phptxt/title.inc'; ?>
							<div id="TitleL">
			  <?php include 'phptxt/google1.inc'; ?>
	    </div>
	  </td>
	</tr><!-- Header END -->
	
	<tr>
		<td width="28" height="773" rowspan="3">
			<img src="images/spacer.gif" width="28" height="773" alt="">		</td>
		
		<td background="images/MIDDLE_03.gif" width="787" height="620"><!-- LOGIN BOX START -->
		  <!-- LOGIN BOX END -->
		  
	<!-- USER ACCOUNT MENU START -->
	<div id="menuposition" background="images/TOP_ContentBoxGreenLeft.gif" width="" height="200">    	
			<?php include 'phptxt/usermenu.inc'; ?><!-- Footer with User Award Details -->
	</div>
	<div id="descriptions" class="menutxt">Welcome Back <?php echo $myusername ?></div>
	<!-- USER ACCOUNT MENU END -->
	
	    <!-- MAIN CONTENT BOX 2 START -->
	<div id="MainContentBox2" background="images/TOP_MainContentBox.gif" width="749" height="284">
		<div>Upload New Images </div>
		<div>
	<?
if ($action=="save") {
if ($i=="") for ($i=1; file_exists("gallery/images/image".strval($i).".jpg"); $i++) {
}
$file ="gallery/des/image$i.txt";
$fp =fopen($file, "w+");
$name=stripslashes($name);
$des=stripslashes($des);
$code=stripslashes($code);
$author=stripslashes($author);
$w ="name=".$name."&price=".$price."&code=".$code."&des=".$des."&author=".$author."&mail=".$mail."&date=".$date."&web=".$web;
for ($ii=1; $ii<100; $ii++) {
$w=stripcslashes($w);
}
if ($down<>"") $w = $w."&counter=0";
fwrite($fp, $w);
fclose($fp);
if (copy($thumb, "gallery/thumbnails/image".strval($i).".jpg"))  echo "Thumbnail copied<br>";
if (copy($image, "gallery/images/image".strval($i).".jpg"))  echo "Image copied<br>";
if (copy($down, "gallery/down/image".strval($i).".zip"))  echo "Download File copied";
} else {
$file="gallery/des/image$i.txt";
///
if (file_exists("gallery/des/image$i.txt")) {
$fp=fopen($file, "r");
$w=fread($fp, filesize($file));
for ($j=1; $j<10; $j++) {
$w=stripcslashes($w);
}
parse_str($w);
$name=stripslashes($name);
$des=stripslashes($des);
$code=stripslashes($code);
$author=stripslashes($author);
fclose($fp);
}
?><form method="post" onSubmit="return validate();" enctype="multipart/form-data" name="form1" action="<?php echo $PHP_SELF;?>">
<p></p>
 <table width="725">
    <tr> 
  		<td colspan="2">		
		</td>
	<td width="146" rowspan="2"> 
		<div align="right"><font size="1" face="verdana">File Source:
		  
		  <input name="i" type="hidden" id="i" value=<?php echo $i;?>>
		  </font> </div></td>
	<td width="222" rowspan="2"><font size="1" face="verdana">
	  <input name="image" type="file" id="image" value='images/image<?php echo $i.'jpg';?>'>
	</font></td>
    </tr>
    <tr>
		<td width="192" height="41">
		  <div align="right"><font size="1" face="verdana"> Name:    	</font> </div></td>
		<td width="145"><font size="1" face="verdana">
		  <input name="name" type="text" id="name" value='<?php echo $name;?>'>
		</font></td>
    </tr>
    <tr>
		<td>		<div align="right"><font size="1" face="verdana">
		  Price :
		  
		  </font> </div></td>
		<td><font size="1" face="verdana">
		  <input name="price" type="text" id="price" value="<?php echo $price;?>">
		</font></td>
		<td width="146"><div align="right"><font size="1" face="verdana">Thumbnail:
		  
		  </font></div></td>
        <td width="222"><font size="1" face="verdana">
          <input name="thumb" type="file" id="thumb" value='thumbnails/image<?php echo $i.'jpg';?>'>
        </font></td>
    </tr>
    <tr>
		<td>
		  <div align="right"><font size="1" face="verdana">Date:
		    
		    <input name="action" type="hidden" id="action" value="save">
		          <input name="password" type="hidden" id="action" value="<?php echo $password;?>">
		      </font> </div></td>
		<td><font size="1" face="verdana">
		  <input name="date" type="text" id="date" value='<?php echo $date;?>'>
		</font></td>
		<td>
				<div align="right"><font size="1" face="verdana">Download File:    	</font> </div></td>
        <td><font size="1" face="verdana">
          <input name="down" type="file" id="down" value='down/image<?php echo $i.'jpg';?>'>
        </font></td>
    </tr>
    <tr>
		<td>
		  <div align="right"><font size="1" face="verdana">Author:</font></div></td>
		<td><input name="author" type="text" id="author" value='<?php echo $author;?>'></td>
		<td rowspan="3">
			<div align="right"><font size="1" face="verdana">Description:</font></div></td>
        <td rowspan="3"><font size="1" face="verdana">
          <textarea name="des" id="des"><?php echo $des;?></textarea>
        </font></td>
    </tr>
	    <tr>
		<td>
		  <div align="right"><font size="1" face="verdana">
		    Author Web:    	</font> </div></td>
		<td><font size="1" face="verdana">
		  <input name="web" type="text" id="web" value='<?php echo $web;?>'>
		</font></td>
	    </tr>
    <tr>
		<td>
		  <div align="right"><font size="1" face="verdana">E-mail:</font></div></td>
		<td><input name="mail" type="text" id="mail" value='<?php echo $mail;?>'></td>
    </tr>
	<tr>
		<td colspan="4"><div align="center"><font size="1" face="verdana">
		  <input type="submit" name="Submit" value="Submit">
		  </font></div></td>
		</tr>
</table>
</P>
</form>
<?php }?>
	</div>
	</div>
	<!-- MAIN CONTENT BOX 2 END -->
 
    <!-- MAIN CONTENT BOX START -->
	<div id="TOP-MainContentBox" background="images/TOP_MainContentBox.gif" width="749" height="284">
		<div>Edit Existing Images </div>
		<div>
		<?
if ($submit=="Edit") {
echo "<script language='JavaScript'>
window.location = 'USERIMAGES.php?i=$choiceimage&password=$password';
</script>";
}elseif ($submit=="Delete") {
for ($i=1; file_exists("gallery/images/image".strval($i).".jpg"); $i++) {
}
$num=$i-1;
function unlinkk($f) {
if (!file_exists($f)) return true;
else return unlink($f);
}
function del($i) {
if (unlinkk("gallery/images/image$i.jpg") and unlinkk("gallery/thumbnails/image$i.jpg") and unlinkk("gallery/down/image$i.zip")
and unlinkk("gallery/des/image$i.txt")) return true;
}
if (!del($choiceimage)) echo "Error";
for ($i=intval($choiceimage)+1; $i<$num; $i--) {
$j=$i-1;
if (!rename("gallery/images/image$i.jpg", "gallery/images/image$j.jpg")) $error="r";
}
if ($error=="") echo "Image$choiceimage deleted successfully";
} else {
echo "<form name=\"form2\" action=\"$PHP_SELF\" method=\"post\">
  <p align=\"center\"><font color=\"#CCCCCC\" size=\"1\" face=\"verdana\"><strong>Select Image<br>
    <table border=0><tr><td><select name=\"choiceimage\" size=7 onChange=\"pre()\">";
       for ($i=1; file_exists("gallery/thumbnails/image".strval($i).".jpg"); $i++) {
    echo "<option value=$i>Image$i</option>";
	}
    echo "</select></td>
    </strong></font></p>
  <p align=center>
    <td><img src=\"gallery/noth.gif\" border=0 name=preview></td></p></tr></table>
  <p align=\"center\"><strong><font color=\"#CCCCCC\" size=\"1\" face=\"verdana\">
    <input type=\"submit\" name=\"submit\" value=\"Edit\">
    <input type=\"hidden\" name=\"password\" value=\"$password\">
    <input type=\"submit\" name=\"submit\" value=\"Delete\">
    </font></strong> </p>
</form>";
}
 
?>
		</div>
	</div>
	<!-- MAIN CONTENT BOX END -->		
	
	</td>
		<td width="15" height="773" rowspan="3">
		<img src="images/spacer.gif" width="15" height="773" alt=""></td>
	</tr>
	
		
	<tr><!-- FOOTER START -->
		<td background="images/MIDDLE_05.gif" width="787" height="141">
			<?php include 'phptxt/footer.inc'; ?><!-- Footer with User Award Details -->		</td>
	</tr><!-- FOOTER END -->
	
	<tr><td width="787" height="12">
	<img src="images/spacer.gif" width="787" height="12" alt=""></td>
	</tr>
</table>
</div>
 
</body>
</html>

Open in new window

LVL 2
Ryan BayneWordPress DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Koma666Commented:
try to add id="form2" to the form and please post the code of the html page from the browser not the php code, it's hard to read the php serverside code with all the variables. It would be easier if you just copy and paste the source code of the web page from your browser.
0
BadotzCommented:
If your "form2" is defined within a <table> element, I don't think that will work. But it is hard to tell, viewing your code :-(
0
Ryan BayneWordPress DeveloperAuthor Commented:
OK I've cleaned up the source code. Tried adding id="form2" but doesnt work.

I considered it being the fact that I use escape code for a form earlier on the page maybe!
<!-- Ryan Bayne -->
<!-- iFolio -->
<!-- All Rights Reserved 2008 -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>iFolio</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="title" content="iFolio By www.webtechglobal.co.uk">
<meta name="description" content="Student resource site">
<meta name="keywords" content=
"designer,web,design,internet,intranet,extranet,looking,for,a,graphics,graphic,logos,logo,low,price,quality,uni,university,scotland,england,uk,kirkcaldy,fife,dundee,perth,webtg,web,tech,technician,technical,global, flash, interactive,banners,ad,banner,page,contact,form,dynamic,static,ryan,zypher,optimization,optimisation,optimize,optimise,photo,photography,law,brunel,saima,khalid,downloads,recordings,lecture">
<link rel="icon" href="favicon.ico" type=
"image/vnd.microsoft.icon">
<link href="css/main.css" rel="stylesheet" type="text/css">
<link href="css/user.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/javascript">
function change(html){
  descriptions.innerHTML=html
}
function pre() {
form2.preview.src = 'gallery/thumbnails/image'+form2.choiceimage.options[form2.choiceimage.selectedIndex].value+'.jpg';
}
</script>
</head>
 
<body>
<div id="Table_01">
<table id="Table_01" width="830" height="926" border="0"
cellpadding="0" cellspacing="0">
<tr><!-- Header START -->
<td width="830" height="153" colspan="3">
<div id="LogID">
<div align="center">You are logged in<br>
<img src="images/Me%20n%20Suit.jpg" width="75" height="82" alt=
"#########"><br>
<a href="/ifolio/loggedout.php">Log Out</a></div>
</div>
<div id="Logo"><img src="images/logo.gif" width="298" height="117"
alt=""></div>
<div id="TitleL"><script type="text/javascript">
<!--
google_ad_client = "pub-4923567693678329";
//GoogleAds 125x125
google_ad_slot = "3166759704";
google_ad_width = 125;
google_ad_height = 125;
google_cpa_choice = ""; // on file
//-->
</script> <script type="text/javascript" src=
"http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
 
</td>
</tr>
<!-- Header END -->
<tr>
<td width="28" height="773" rowspan="3"><img src=
"images/spacer.gif" width="28" height="773" alt=""></td>
<td background="images/MIDDLE_03.gif" width="787" height="620">
<!-- LOGIN BOX START -->
<!-- LOGIN BOX END -->
<!-- USER ACCOUNT MENU START -->
<div id="menuposition" background=
"images/TOP_ContentBoxGreenLeft.gif" width="" height="200">
<ul id="usermenu">
<li><a href='Account.php' onmouseover=
"javascript:change('View and manage your personnel information from here')"
onmouseout=
"javascript:change('Remember to always Log-Out when finished')">Account</a></li>
<li><a href='Friends.php' onmouseover=
"javascript:change('Connect to friends interact with each others profiles')"
onmouseout=
"javascript:change('Please change your password regularly')">Friends</a></li>
<li><a href='Sales.php' onmouseover=
"javascript:change('View your sales information both purchases and sold items')"
onmouseout=
"javascript:change('You can use Paypal to buy and sell')">Sales</a></li>
 
<li><a href='Portfolio.php' onmouseover=
"javascript:change('Manage your portfolio and CV from here')"
onmouseout=
"javascript:change('Remember to update your portfolio')">Portfolio</a></li>
<li><a href='USERFILES.php' onmouseover=
"javascript:change('Upload, organise and set file settings in here')"
onmouseout=
"javascript:change('With premium services you can upload larger files')">
Files</a></li>
<li><a href='Mail.php' onmouseover=
"javascript:change('Send mail to other members or iFolio')"
onmouseout=
"javascript:change('Never send personal information to other users')">
Mail</a></li>
<li><a href='forum/index.php' onmouseover=
"javascript:change('Visit the user forum and discuss anythign you like')"
onmouseout=
"javascript:change('People can be very helpfull in the forum')">Forum</a></li>
<li><a href='USERCHAT.php' onmouseover=
"javascript:change('Chat with other members who are online now')"
onmouseout=
"javascript:change('Our chat service is very safe and secure')">Chat</a></li>
<li><a href='stats.php' onmouseover=
"javascript:change('View stats on profile views, log time, sales and much more')"
onmouseout=
"javascript:change('You can win things on the stats page')">My
Stats</a></li>
<li><a href='settings.php' onmouseover=
"javascript:change('Personnel settings to make iFolio work the way you want')"
onmouseout=
"javascript:change('Personalise your profile and shop')">Settings</a></li>
</ul>
 
<!-- Footer with User Award Details --></div>
<div id="descriptions" class="menutxt">Welcome Back test1</div>
<!-- USER ACCOUNT MENU END -->
<!-- MAIN CONTENT BOX 2 START -->
<div id="MainContentBox2" background=
"images/TOP_MainContentBox.gif" width="749" height="284">
<div>Upload New Images</div>
<div>
<form method="post" onsubmit="return validate();" enctype=
"multipart/form-data" name="form1" action="/ifolio/userimages.php">
<table width="725">
<tr>
<td colspan="2"></td>
<td width="146" rowspan="2">
<div align="right"><font size="1" face="verdana">File Source:
<input name="i" type="hidden" id="i" value=""></font></div>
</td>
 
<td width="222" rowspan="2"><font size="1" face=
"verdana"><input name="image" type="file" id="image" value=
'images/imagejpg'></font></td>
</tr>
<tr>
<td width="192" height="41">
<div align="right"><font size="1" face="verdana">Name:</font></div>
</td>
<td width="145"><font size="1" face="verdana"><input name="name"
type="text" id="name" value=''></font></td>
</tr>
<tr>
<td>
<div align="right"><font size="1" face="verdana">Price
:</font></div>
</td>
<td><font size="1" face="verdana"><input name="price" type="text"
id="price" value=""></font></td>
<td width="146">
<div align="right"><font size="1" face=
"verdana">Thumbnail:</font></div>
 
</td>
<td width="222"><font size="1" face="verdana"><input name="thumb"
type="file" id="thumb" value='thumbnails/imagejpg'></font></td>
</tr>
<tr>
<td>
<div align="right"><font size="1" face="verdana">Date: <input name=
"action" type="hidden" id="action" value="save"> <input name=
"password" type="hidden" id="action" value=""></font></div>
</td>
<td><font size="1" face="verdana"><input name="date" type="text"
id="date" value=''></font></td>
<td>
<div align="right"><font size="1" face="verdana">Download
File:</font></div>
</td>
<td><font size="1" face="verdana"><input name="down" type="file"
id="down" value='down/imagejpg'></font></td>
</tr>
<tr>
 
<td>
<div align="right"><font size="1" face=
"verdana">Author:</font></div>
</td>
<td><input name="author" type="text" id="author" value=''></td>
<td rowspan="3">
<div align="right"><font size="1" face=
"verdana">Description:</font></div>
</td>
<td rowspan="3"><font size="1" face="verdana">
<textarea name="des" id="des">
</textarea></font></td>
</tr>
<tr>
<td>
<div align="right"><font size="1" face="verdana">Author
Web:</font></div>
 
</td>
<td><font size="1" face="verdana"><input name="web" type="text" id=
"web" value=''></font></td>
</tr>
<tr>
<td>
<div align="right"><font size="1" face=
"verdana">E-mail:</font></div>
</td>
<td><input name="mail" type="text" id="mail" value=''></td>
</tr>
<tr>
<td colspan="4">
<div align="center"><font size="1" face="verdana"><input type=
"submit" name="Submit" value="Submit"></font></div>
</td>
</tr>
</table>
</form>
 
</div>
</div>
<!-- MAIN CONTENT BOX 2 END -->
<!-- MAIN CONTENT BOX START -->
<div id="TOP-MainContentBox" background=
"images/TOP_MainContentBox.gif" width="749" height="284">
<div>Edit Existing Images</div>
<div>
<form id="form2" name="form2" action="/ifolio/userimages.php"
method="post">
<p align="center"><font color="#CCCCCC" size="1" face=
"verdana"><strong>Select Image<br></strong></font></p>
<p align="center"></p>
<table border="0">
<tr>
<td><select name="choiceimage" size="7" onchange="pre()">
<option value="1">Image1</option>
 
<option value="2">Image2</option>
<option value="3">Image3</option>
<option value="4">Image4</option>
</select></td>
<td><img src="gallery/noth.gif" border="0" name="preview" alt=
"#########"></td>
</tr>
</table>
<p align="center"><font color="#CCCCCC" size="1" face=
"verdana"><strong><strong><font color="#CCCCCC" size="1" face=
"verdana"><input type="submit" name="submit" value="Edit">
<input type="hidden" name="password" value=""> <input type="submit"
name="submit" value="Delete"></font></strong></strong></font></p>
</form>
</div>
</div>
<!-- MAIN CONTENT BOX END --></td>
 
<td width="15" height="773" rowspan="3"><img src=
"images/spacer.gif" width="15" height="773" alt=""></td>
</tr>
<tr><!-- FOOTER START -->
<td background="images/MIDDLE_05.gif" width="787" height="141">
<div id="TOP-FootHead1" width="230" height="111">
<div>Annual User Award</div>
<p>ZypheR2006 won top user for 2007 and was awarded 5000
credits!!!</p>
</div>
<div class="style1" id="TOP-FootHead2" background=
"images/TOP_FootHead2.gif" width="230" height="111">
<div>Monthly User Award</div>
<p>MaryPoppins was Decembers winner for the free access to all
tools</p>
</div>
<div id="TOP-FootHead3" background="images/TOP_FootHead3.gif"
width="230" height="111">
 
<div>Weekly User Award</div>
<p>DrDre2001's ifolio use for last week wins him 100 credits.</p>
</div>
<!-- Footer with User Award Details --></td>
</tr>
<!-- FOOTER END -->
<tr>
<td width="787" height="12"><img src="images/spacer.gif" width=
"787" height="12" alt=""></td>
</tr>
</table>
</div>
</body>
</html>

Open in new window

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Ryan BayneWordPress DeveloperAuthor Commented:
looks a mess!!!!!
0
v2MediaCommented:
Try overwriting your js functions with those below, and give the preview image an id tag:

<img src="gallery/noth.gif" border="0" name="preview" id="preview" alt="#########">
<script language="JavaScript" type="text/javascript">
function change(html){
	document.getElementById('descriptions').innerHTML=html;
}
function pre() {
	document.form2.preview.src = 'gallery/thumbnails/image' + document.form2.choiceimage.options[document.form2.choiceimage.selectedIndex].value+'.jpg';
}
</script>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
v2MediaCommented:
correction:
<script language="JavaScript" type="text/javascript">
function change(html){
	document.getElementById('descriptions').innerHTML=html;
}
function pre() {
	document.getElementById('preview').src = 'gallery/thumbnails/image' + document.form2.choiceimage.options[document.form2.choiceimage.selectedIndex].value+'.jpg';
}
</script>

Open in new window

0
Ryan BayneWordPress DeveloperAuthor Commented:
That works a treat. Next I need to figure out why changing the scripts environment made it not work thanks for that

:-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.