4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 setTimeout with quotation marks does not work
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
duski
Junior WebHelper
Junior WebHelper


Joined: 02 Dec 2003
Posts: 1

PostPosted: Tue Dec 02, 2003 11:11 am (13 years, 10 months ago) Reply with QuoteBack to Top

Can anybody help me with this problem? I have a javascript function that uses the setTimeout command at some point. However, when I use the command incorporating quotation marks for the first argument, as in:
setTimeout("loadNav(pageNumber)", 3000);
it does not work. If I leave the qotation marks off, my code gets executed correctly but then a javascript error message pops up, complaining about my invalid argument. I have tried escaping the quotation marks with a backslash but then I get a complaint about an invalid character. I don't know what to do!
Any help would be greatly appreciated - below is the full code of my function:

function loadSmith(book, page) {
if ((book == "")|(page == "")){
alert("Please choose a book AND an edition to view");
}
else {
var name = page.lastIndexOf("/");
var pageNumber = page.substring(name+1,name+5);
parent.manus.location.href="http://www.shef.ac.uk/smith/documents/" + book + page;
setTimeout(loadNav(pageNumber), 3000);
}
}
OfflineView User's ProfileFind all posts by duskiSend Personal Message
jedioutcaster
Junior WebHelper
Junior WebHelper


Joined: 23 Dec 2003
Posts: 4

PostPosted: Tue Dec 23, 2003 10:08 am (13 years, 10 months ago) Reply with QuoteBack to Top

In case you haven't gotten any reply from elsewhere, I can give you some help. Yesterday, I was having the same problem ---> "Line ** ... Invalid Argument". Was that it? Anyway, since this is not a native JavaScript function (it's HTML function), you'll have to enclose the expression of your function within non-conflicting quotation marks. So, in this case:

setTimeout("loadNav("+pageNumber+")", 3000);

Notice the bold-faced area. You'll have to indicate the pageNumber by direct definition input (what i mean is just put the number in instead of the variable "pageNumber") and not the number (you might wanna try, probably it'll work; but it won't work when you use a property of the pageNumber later on and it'll tell you invalid property).

Anywayz, blahing nonsense Razz

Did that help? I hope so. C ya!
OfflineView User's ProfileFind all posts by jedioutcasterSend Personal Message
php4ever
Junior WebHelper
Junior WebHelper


Joined: 10 Oct 2002
Posts: 49

PostPosted: Mon Dec 29, 2003 10:05 pm (13 years, 9 months ago) Reply with QuoteBack to Top

I, too, have gone thru the ordeal of trying to pass a variable as a parameter with setTimeout.

Good news is that it can be done. Below are two examples that work:

<head>
<script>
var num = 1
var c = "a"
function AddNum(n)
{
n = n + 2;
alert(n);
}
function DoIt()
{
setTimeout("AddNum(" + num + ")", 1000);
}
function DoThis()
{
setTimeout("AddNum('" + c + "')", 1000);
}
</script>
</head>

<body>
<input type=button value="Adding 1 + 2" onclick="DoIt()"><p>
<input type=button value="Concatenating 'a' and '2'" onclick="DoThis()">
</body>

In re the script in question perhaps if you try recoding your script with the quotes as I've done above, your script might work. Note how I've made the parameters global variables by declaring them above outside any function.

BTW, where is the code to your function that setTimeout calls? I'd be curious as to what that looks like to see how the whole thing should work.

All best regards,
PHP4ever
OfflineView User's ProfileFind all posts by php4everSend Personal Message
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   




You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot edit your posts in this forum.
You cannot delete your posts in this forum.
You cannot vote in polls in this forum.


Page generation time: 0.057293 seconds :: 17 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme