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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting variables and calling the script

Status
Not open for further replies.

dthievin

Instructor
Feb 3, 2001
13
0
0
CA
First, I’m COMPLETELY a javascript novice, so please endure. Here’s my dilemma:

I’m creating a single javascript called “project.js” in its own directory that I’d like to call from my html for any number of links:

var name="john";
var name="joe";
var name="jack";

function askjohn(){var win=window.open('txt-john.htm','askwinjohn',',scrollbars=no,height=250,width=230');if(!win.opener)win.opener=self}document.write('<a href="javascript:void(0)" onclick="askjohn()">John</a>');

function askjoe(){var win=window.open('txt-joe.htm','askwinjoe',',scrollbars=no,height=250,width=230');if(!win.opener)win.opener=self}document.write('<a href="javascript:void(0)" onclick="askjoe()">Joe</a>');

function askjack(){var win=window.open('txt-jack.htm','askwinjack',',scrollbars=no,height=250,width=230');if(!win.opener)win.opener=self}document.write('<a href="javascript:void(0)" onclick="askjack()">Jack</a>');


I’ve put this line in the header of my html:

<script type="text/javascript" language="JavaScript"src="/scripts/project.js"></script>

Now, I’m sure you javascript whizzes are chuckling at this feeble attempt and for good reason. It doesn’t work because at the top of my rendered page I get a line that looks like this: JohnJoeJack. I have the feeling I could also reduce the three paragraphs in my java to just one, but I haven’t a clue how.

I’d be eternally grateful if someone would point me in the right direction.
 
Fendal:

This actually works!

Now, for the sake of organization on a messy page, if I want to create the script as a standalone .js file, would it not look like this?

// JavaScript

function ask(person){
window.open(+person, "askwin","scrollbars=no, height=250, width=250");
}

You see, this is what I've been trying to do all along. So now I've created this in the html header:

<script type="text/javascript" language="JavaScript" src="/scripts/project.js"></script>

... but when clicking on the link, nothing happens. I presume I'm missing some code in the JS.

-dt-
 
Did you say earlier that you get an "Error on page" message? What else does it say? What is the URL of the page the error is on and what line?

You're sure your .js file does NOT have the <script></script> tags in it? You seem to indicate that it does not, but just to be sure...

Dave

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...east is east and west is west and if you take cranberries and stew them like applesauce
they taste much more like prunes than rhubarb does
[infinity]
 
There is no new URL. When the link ...

<a href="javascript:ask('txt-john.html')">John</a>

... is clicked, neither IE nor FireFox go anywhere. However, IE displays the message on the bottom toolbar, "Error on page."

There are no <script></script> tags in the script. It's exactly as shown. Again, I'm wondering if this is about paths?
 
There should be alittle yellow exclamation point next to the "error on page" message. Double-click on that. A more-detailed message will pop up.

Dave

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...east is east and west is west and if you take cranberries and stew them like applesauce
they taste much more like prunes than rhubarb does
[infinity]
 
if you're not using the full url remove the plus sign,

Code:
function ask(person){
window.open([COLOR=red]+[/color]person, "askwin","scrollbars=no, height=250, width=250");
}

so it's

Code:
function ask(person){
window.open(person, "askwin","scrollbars=no, height=250, width=250");
}

failing that check all the spellings and make sure the "project.js" file is in the "scripts" folder.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top