Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with .js file 1

Status
Not open for further replies.

PrayingMantus

Vendor
Aug 8, 2003
40
AU
Hi guys I was wondering if I could get some help with this javascript code, I need to call it from the server as a .js file but I can't seem to get it to work, I must be creating the file wrong but I don't know how? Below is the code that needs to be a .js

Code:
<table width="100%"  border="0">
      <tr>
        <td height="25"><div align="center">
		</div></td>
      </tr>
    </table>
	<form name="dailyinfo"><table border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="100%"><font size=4 face=Verdana><b>Information&nbsp;&nbsp;</b></font>
<br><textarea name="dailycontent" cols="50" rows="5" wrap="VIRTUAL"></textarea></td>
    </tr>
    <tr>
      <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
        <tr>
          <td width="35%"><a href="javascript:moreinfo()">More Information</a></td>
		  <td width="65%"><div align="right"></td>
        </tr>
      </table>
      </td>
    </tr>
  </table>
</form><script>
<!--

var dailyinfo=new Array()
var dailyinfolink=new Array()


dailyinfo[1]='bla bla bla'
dailyinfo[2]='bla bla bla'
dailyinfo[3]='bla bla bla'
dailyinfo[4]='bla bla bla'
dailyinfo[5]='bla bla bla'
dailyinfo[6]='bla bla bla'
dailyinfo[7]='bla bla bla'
dailyinfo[8]='bla bla bla'
dailyinfo[9]='bla bla bla'
dailyinfo[10]='bla bla bla'
dailyinfo[11]='bla bla bla'
dailyinfo[12]='bla bla bla'
dailyinfo[13]='bla bla bla'
dailyinfo[14]='bla bla bla'
dailyinfo[15]='bla bla bla'
dailyinfo[16]='bla bla bla'
dailyinfo[17]='bla bla bla'
dailyinfo[18]='bla bla bla'
dailyinfo[19]='bla bla bla'
dailyinfo[20]='bla bla bla'
dailyinfo[21]='bla bla bla'
dailyinfo[22]='bla bla bla'
dailyinfo[23]='bla bla bla'
dailyinfo[24]='bla bla bla'
dailyinfo[25]='bla bla bla'
dailyinfo[26]='bla bla bla'
dailyinfo[27]='bla bla bla'
dailyinfo[28]='bla bla bla'
dailyinfo[29]='bla bla bla'
dailyinfo[30]='bla bla bla'
dailyinfo[31]='bla bla bla'

dailyinfolink[28]="[URL unfurl="true"]http://"[/URL]
dailyinfolink[29]="[URL unfurl="true"]http://"[/URL]

var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()+1
if (month<10)
month="0"+month
var daym=mydate.getDate()


document.dailyinfo.dailycontent.value=dailyinfo[daym]

function moreinfo(){
if (dailyinfolink[daym])
window.location=dailyinfolink[daym]
else
alert("No additional information available for this piece")
}

//-->
</script>
 

You cannot include HTML in a JS file. The only things you can include is JavaScript... Don't even include the open and closing script tags.

Hope this helps,
Dan
 
Well... by the looks of it you are running this Javascript code before the page has finished loading. This can lead to some unexpected behaviour (since you are attempting to manipulate DOM elements - specifically accessing the dailycontent input value).

I suggest you move some of the code into a function, and call that function in the onload of the document.

You never actually explained what your problem was (other than "can't seem to get it to work". Does it give errors (if so, what are they)?

I suggest that you try simplifying your code right down to the most basic elements that you *need* to test the Javascript code. It will make it easy for others to view your code (and help debug) and will help when applying changes (for testing) suggested here (and you can add back in all the "fluff" once you know it works).

Jeff
 
To add to what Dan has posted... are you maybe confusing a SSI (server-side include) file with a JS include file?

You *can* include HTML in SSI files... just as you have pasted... but this is nothing to do with JS include files.

Jeff
 
Basically, do not include any of the HTML code, open/close script, and script-hiding comment tags in your JS file... so out of your code above, only this would go into the file:

Code:
var dailyinfo = new Array();
var dailyinfolink = new Array();

dailyinfo[1] = 'bla bla bla';
dailyinfo[2] = 'bla bla bla';
dailyinfo[3] = 'bla bla bla';
dailyinfo[4] = 'bla bla bla';
dailyinfo[5] = 'bla bla bla';
dailyinfo[6] = 'bla bla bla';
dailyinfo[7] = 'bla bla bla';
dailyinfo[8] = 'bla bla bla';
dailyinfo[9] = 'bla bla bla';
dailyinfo[10] = 'bla bla bla';
dailyinfo[11] = 'bla bla bla';
dailyinfo[12] = 'bla bla bla';
dailyinfo[13] = 'bla bla bla';
dailyinfo[14] = 'bla bla bla';
dailyinfo[15] = 'bla bla bla';
dailyinfo[16] = 'bla bla bla';
dailyinfo[17] = 'bla bla bla';
dailyinfo[18] = 'bla bla bla';
dailyinfo[19] = 'bla bla bla';
dailyinfo[20] = 'bla bla bla';
dailyinfo[21] = 'bla bla bla';
dailyinfo[22] = 'bla bla bla';
dailyinfo[23] = 'bla bla bla';
dailyinfo[24] = 'bla bla bla';
dailyinfo[25] = 'bla bla bla';
dailyinfo[26] = 'bla bla bla';
dailyinfo[27] = 'bla bla bla';
dailyinfo[28] = 'bla bla bla';
dailyinfo[29] = 'bla bla bla';
dailyinfo[30] = 'bla bla bla';
dailyinfo[31] = 'bla bla bla';

dailyinfolink[28] = '[URL unfurl="true"]http://';[/URL]
dailyinfolink[29] = '[URL unfurl="true"]http://';[/URL]

var mydate = new Date();
var year = mydate.getYear();
if (year < 1000) year += 1900;
var day = mydate.getDay();
var month = mydate.getMonth() + 1;
if (month<10) month = '0' + month;
var daym = mydate.getDate()

document.dailyinfo.dailycontent.value = dailyinfo[daym];

function moreinfo(){
	if (dailyinfolink[daym]) {
		window.location = dailyinfolink[daym];
	} else {
		alert('No additional information available for this piece');
	}
}

And then you would include that script file thus:

Code:
<script type="text/javascript" src="yourJsFilename.js"></script>

Hope this helps,
Dan
 
Thanks heaps guys that worked a treat! It worked nicely for that code but doesn't work for this other code that I also need to make external javascript file.
The code (shortened) that normally goes into the page body is:
Code:
<script type='text/javascript'>
function Go(){return}

</script>
<noscript>Your browser does not support script</noscript>
I then created the .js file & changed the code (shortened) to this:
Code:
function Go(){return}

<noscript>Your browser does not support script</noscript>
I then put this: "<script type="text/javascript" src="menu.js"></script>" exactly where I want the menu to appear, however it is not showing, anyone know why?
 

You cannot have anything in a JS file that isn't JS - and that inclueds the "NOSCRIPT" HTML tag.

You should keep the NOSCRIPT tag in your HTML page.

Hope this helps,
Dan
 
Thanks heaps BillyRayPreachersSon! That did the trick, yeah I really wanted those NOSCRIPT tags in for some reason :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top