Timeout with Java script

new BookmarkLockedFalling
marcioc
Junior Member
**

marcioc Avatar

Posts: 60

Post by marcioc on Aug 29, 2010 18:43:43 GMT -5

who knows why this works:

 cls
link #q,"aaa",[test]
html "<script type=""text/javascript"">
var a = null;
var timer;
var as = document.getElementsByTagName('A');
for (var i = 0; i < as.length; i++)
{
if (as.firstChild.data == 'aaa')
{
a = as;
break;
}
}
if (a) timer = setTimeout('location = a.href',500);
</script>"
wait
[test]
cls
print "Worked"


and this does not work?

 cls
link #q,"aaa",[test]
html "<script type=""text/javascript""> function inform() {
var a = null;
var timer;
var as = document.getElementsByTagName('A');
for (var i = 0; i < as.length; i++)
{
if (as.firstChild.data == 'aaa')
{
a = as;
break;
}
}
if (a) timer = setTimeout('location = a.href',500);} </script>"

html "<form> <input type='button' name='testx' value='Click me' onclick='inform()'> </form>"
wait
[test]
cls
print "Worked"

Thanks in advance.
Last Edit: Aug 30, 2010 9:55:36 GMT -5 by StefanPendl
StefanPendl
Global Moderator
*****

StefanPendl Avatar

Run for BASIC ...
Posts: 945

[b]Stefan[/b] - [a href=http://stefanpendl.runbasichosting.com/]Homepage[/a][br][br][b]Please give credit if you use code I post, no need to ask for permission.[/b][br][br]Run BASIC 1.01, Fire-/Waterfox (IE11, Edge), Windows 10 Professional x64, Intel Core i7-4710MQ 2.5GHz, 16GB RAM
marcioc
Junior Member
**

marcioc Avatar

Posts: 60

marcioc
Junior Member
**

marcioc Avatar

Posts: 60

Post by marcioc on Aug 30, 2010 14:05:26 GMT -5

I just defined var a in the body of the java script and it worked.

 cls
link #q,"aaa",[test]
html "<script type=""text/javascript"">
var a=null;
function inform() {
var timer;
var as = document.getElementsByTagName('A');
for (var i = 0; i < as.length; i++) {
if (as.firstChild.data == 'aaa')
{
a = as;
break;
}
}
if (a) timer = setTimeout('location = a.href',500); }
</script> "
html "<form> <input type='button' name='testx' value='Click me' onclick='inform()'> </form>"
wait
[test]
cls
print "Worked"
Last Edit: Aug 31, 2010 4:05:33 GMT -5 by StefanPendl