Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Runtime error

Reply
Thread Tools

Runtime error

 
 
alistair@nts-graphics.co.uk
Guest
Posts: n/a
 
      02-16-2005
Hi all,

The following JS function gives a runtime error - 'Error myButton is
undefined' when the function tries to call itself.

The function basically tries to [simply] animate a buttons text to show
the user that something is happening . . .

function buttonText(myButton) {
var A='/', B='-', C='\\', D='|';
var Text=eval(myButton+'.value');
switch (Text) {
case '|':
eval(myButton+'.value=A');
break;
case '/':
eval(myButton+'.value=B');
break;
case '-':
eval(myButton+'.value=C');
break;
default:
eval(myButton+'.value=D');
break;
}
setTimeout('buttonText(myButton)',150);
}

 
Reply With Quote
 
 
 
 
Erwin Moller
Guest
Posts: n/a
 
      02-16-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> Hi all,
>
> The following JS function gives a runtime error - 'Error myButton is
> undefined' when the function tries to call itself.
>
> The function basically tries to [simply] animate a buttons text to show
> the user that something is happening . . .
>
> function buttonText(myButton) {
> var A='/', B='-', C='\\', D='|';
> var Text=eval(myButton+'.value');
> switch (Text) {
> case '|':
> eval(myButton+'.value=A');
> break;
> case '/':
> eval(myButton+'.value=B');
> break;
> case '-':
> eval(myButton+'.value=C');
> break;
> default:
> eval(myButton+'.value=D');
> break;
> }
> setTimeout('buttonText(myButton)',150);
> }


Hi,

I think in your call:
setTimeout('buttonText(myButton)',150);
button doesn't contain the original value (a reference to a button??).

You better rewrite your code and pass a number of string to the function.

setTimeout('buttonText(1)',150);

Of course you'll have to change the function too, so it understands 1.
when receiving 1, set 2 in the timeout-call.
etc.

Regards,
Erwin Moller
 
Reply With Quote
 
 
 
 
RobB
Guest
Posts: n/a
 
      02-16-2005
function buttonText(button_id)
{
var b = document.getElementById(button_id);
if (b)
{
switch (b.value)
{
case '|' :
b.value = '/';
break;
case '/' :
b.value = '-';
break;
case '-' :
b.value = '\\';
break;
default :
b.value = '|';
}
}
}

setTimeout('buttonText("button1")', 150);

<input id="button1"...../>

 
Reply With Quote
 
RobB
Guest
Posts: n/a
 
      02-16-2005
OK, had a little fun here. See if there's anything you can use. =

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>untitled</title>
<style type="text/css">

..button {
width: 60px;
font: bold 14px tahoma;
color: #060;
background: #efe0b8;
}

</style>
<script type="text/javascript">

var B =
{
timer : null ,
active : false ,
curr : null ,
nglyph : 0 ,
glyphs : ['|','/','--','\\']
}

function butspin(but)
{
init();
if (!B.active && but != B.curr)
{
but.origValue = but.value;
B.active = true;
B.curr = but;
B.timer = setInterval(animate, 100);
}
else B.curr = null;
}

function animate()
{
B.curr.value = B.glyphs[B.nglyph++ % 4];
}

function init()
{
if (B.timer)
{
clearInterval(B.timer);
B.active = false;
}
if (B.curr && B.curr.origValue)
B.curr.value = B.curr.origValue;
B.nglyph = 0;
}

onunload = init;

</script>
</head>
<body style="margin:100px;">
<hr />
<form>
<input id="button1"
class="button"
type="button"
value="foo"
onfocus="this.blur()"
onclick="butspin(this)" />
<input id="button2"
class="button"
type="button"
value="feh"
onfocus="this.blur()"
onclick="butspin(this)" />
<input id="button3"
class="button"
type="button"
value="hah"
onfocus="this.blur()"
onclick="butspin(this)" />
<input
class="button"
type="button"
value="stop"
style="color:#600;margin-left:5px;"
onfocus="this.blur()"
onclick="init()" />
</form>
<hr />
</body>
</html>

 
Reply With Quote
 
alistair@nts-graphics.co.uk
Guest
Posts: n/a
 
      02-17-2005
Thanks guys, the last solution did the trick

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help: Runtime Error - Server Error in '/' Application Kevin Farless ASP .Net 13 10-03-2007 09:48 AM
Runtime.exec(String[]) Doesn't Always Work, bBut Runtime.exec(String) Does Hal Vaughan Java 11 05-22-2006 04:49 PM
Server Error in '/' Application. Runtime Error. Krunom Ancini ASP .Net 2 03-01-2005 10:07 AM
where can i find the lines of error in Runtime Error Page? Yongsub Eric Shin ASP .Net 7 01-14-2004 12:29 AM
fatal error CS0007: Unexpected common language runtime initialization error -- Polo Lee ASP .Net 0 07-07-2003 01:24 AM



Advertisments