...

View Full Version : external js not loading with php switched div



Bambam007
10-03-2008, 06:43 AM
Hi all,

I have a page with a couple of navigation buttons.
the buttons are used to load and external page into the div using a php script
the scripts used case 1 case 2 case 3 etc. It works.

The problem is that my otherwise working Java Script does not work or load with this set up. it is an external .js file that i call in the header of the base page.

Is there a reason that it will not load properly now?

abduraooft
10-03-2008, 07:02 AM
Post your code, or a link to your page would be better.

Bambam007
10-03-2008, 07:37 AM
Of course sorry here is the code


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Contact Information</title>
<meta http-equiv="Content-Style-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript" src="http://www.website.com.au/js/contact.js"></script>
<script type="text/javascript" src="http://www.website.com.au/js/template.js"></script>

<link rel="stylesheet" href="http://www.website.com.au/css/contact.css" type="text/css" media=screen>
<link rel="stylesheet" href="http://www.website.com.au/css/contact_info.css" type="text/css" media=screen>
<?
switch ($_GET['page'])
{
case "main": include ('http://www.website.com.au/contact_info.php'); break;
case "2": include ('http://www.website.com.au/contact_email.php'); break;
case "3": include ('http://www.website.com.au/contact_map.php'); break;
case "4": include ('http://www.website.com.au/contact_aboutus.php'); break;
case "5": include ('http://www.website.com.au/contact_feedback.php'); break;
case "6": include ('http://www.website.com.au/contact_refer.php'); break;

default: include ('http://www.website.com.au/contact_info.php'); break;
}
?>
</head>
<body bgcolor="#GGGGGG" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<div id="table_contact">
<div id="cftemplate"><? include("http://www.website.com.au/template.php"); ?></div>
<div id="cfcontact-template"><? include("http://www.website.com.au/contact_template.php"); ?></div>

<?
switch ($_GET['page'])
{
case "main": include ('http://www.website.com.au/contact_info.php'); break;
case "2": include ('http://www.website.com.au/contact_email.php'); break;
case "3": include ('http://www.website.com.au/contact_map.php'); break;
case "4": include ('http://www.website.com.au/contact_aboutus.php'); break;
case "5": include ('http://www.website.com.au/contact_feedback.php'); break;
case "6": include ('http://www.website.com.au/contact_refer.php'); break;

default: include ('http://www.website.com.au/contact_info.php'); break;
}
?>
</div>
</body>
</html>


NB the included template file has the nav buttons which change the case

And here is one of the case included pages



<!-- Email Section -->
<div>
<form name="emailform" id="emailform" method="post" action="http://www.website.com.au/contact_email_sendmail.php">
<div><input class="email-name" type="text" size="30" maxlength="50" name="ename" value="your name" onfocus="value=''"></div>
<div><input class="email-email" type="text" size="30" maxlength="50" name="eemail" value="your email address" onfocus="value=''"></div>
<div><input class="email-subject" type="text" size="30" maxlength="50" name="esubject" value="subject" onfocus="value=''"></div>
<div><textarea id="email-textarea" name="ebody" onfocus="value=''" rows="0" cols="0" onkeydown="limitText(this,400);" onKeyUp="limitText(this,400);"></textarea></div>
<div id="email-sendmessage"><input type="image" name="esubmit"><a href="javascript: emailsubmit()" onclick="return emailvalidate()"></a></div>
</form>
</div>
<div id="email-details"></div>
<div id="email-rollaway" onmouseout="emailout()"></div>
<!-- End Email Section -->



And here is the linked java script file



/*-------- Email -----------------------------------------*/
/*--- Email out---*/
function emailout() {
if (document.emailform.ename.value.length == 0){
document.emailform.ename.value="your name";
return false;
}
if (document.emailform.eemail.value.length == 0){
document.emailform.eemail.value="your email address";
return false;
}
if (document.emailform.esubject.value.length == 0){
document.emailform.esubject.value="subject";
return false;
}
return true;
}

/*-- Email submit---*/
function emailsubmit(){
document.emailform.submit();
}

/*-- Email validate---*/
function emailvalidate() {
if (document.emailform.eemail.value.length < 5) {

alert("Please enter your email address");
document.emailform.eemail.focus();
return false;
}
if (document.emailform.eemail.value.indexOf('@') == -1) {
alert("Your E-Mail address does not appear to be valid");
document.emailform.eemail.focus();
return false;
}
if (document.emailform.eemail.value.indexOf('.') == -1) {
alert("Your E-Mail address does not appear to be valid");
document.mailform.eemail.focus();
return false;
}
if (document.emailform.esubject.value.length < 4) {
alert("Please enter a meaningful subject");
document.emailform.esubject.focus();
return false;
}
if (document.emailform.esubject.value == 'subject') {
alert("Please enter a meaningful subject");
document.emailform.esubject.focus();
return false;
}
if (document.emailform.ebody.value.length < 15) {
alert("Please enter a meaningful body");
return false;
}
if (document.emailform.ename.value.length < 1) {
alert("Please enter your name");
document.emailform.ename.focus();
return false;
}
if (document.emailform.ename.value == 'your name') {
alert("Please enter your name");
return false;
}
return true;
}

Bambam007
10-03-2008, 07:40 AM
Also note that when I had the cases as separate pages (no case switching) the javascript was working

Bambam007
10-03-2008, 08:53 AM
OMG I'm a huge silly person.

I called the script twice!, no wonder it wasn't working. But thank you anyway because without showing you i may not have fixed it!


Phew

abduraooft
10-03-2008, 12:53 PM
lol! You're welcome (to Codingforums.com too :) )



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum