473,769 Members | 2,331 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do you stop a javascript program?

While running a program that exceeds the array limits it issues an
alert. I want to then stop the program after filling in the output
boxes with blanks. How do you stop the program?
I have worked on this for days and tried searching the net, but have
found nothing.

Mar 4 '06 #1
14 7474
I jsut searched groups for stop javascript and found the answer. The
answer is to label loops and then use a break loop statement.

Mar 4 '06 #2
el*********@ele ctrician.com wrote:

[Added attribution and quotation]
el*********@ele ctrician.com wrote:
While running a program that exceeds the array limits it issues an
alert. I want to then stop the program after filling in the output
boxes with blanks. How do you stop the program?
You don't.
I have worked on this for days and tried searching the net, but have
found nothing.


I jsut searched groups for stop javascript and found the answer.
The answer is to label loops and then use a break loop statement.

^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^
No, this reads like utter nonsense. If I understood your OP correctly,
which you did not quote BTW[1], you should use something like

var es = f.elements;
for (var i = 0, len = es.length; i < len; i++)
{
// ... es[i] ...
}

Provided that `f' refers to a HTMLFormElement representing a `form' element
your "output boxes" are controls of. Where you should know that you are
not dealing with an Array object, but with an HTMLCollection object.
PointedEars
_________
[1] <URL:http://safalra.com/special/googlegroupsrep ly/>
Mar 4 '06 #3
The problem was that I searched an array of conductor ampacities, but
when the end of the array was reached and the right size conductor
could not be found because the derating was too high I needed to stop
the program and alert the user to enter smaller values and fill all the
output form values with blanks and terminate the program. I
accomplished this by setting a flag to True and broke out of the outer
loop with break loop then filled in the blanks by running the
endprogram when the flag is true. It works just fine, now. This is a
rather long program and I have obfuscated it, but if you want to see it
work it is at,
http://electrician.com/calculators/wireocpd_ver_1.html

Mar 5 '06 #4
el*********@ele ctrician.com wrote:
The problem was that I searched an array of conductor ampacities, but
when the end of the array was reached and the right size conductor
could not be found because the derating was too high I needed to stop
the program and alert the user to enter smaller values and fill all the
output form values with blanks and terminate the program. I
accomplished this by setting a flag to True and broke out of the outer
loop with break loop then filled in the blanks by running the
endprogram when the flag is true. It works just fine, now. This is a
rather long program and I have obfuscated it, but if you want to see it
work it is at,
http://electrician.com/calculators/wireocpd_ver_1.html


I will not pretend that I fully understand what you are talking about, since
I am not an electrician, and your explanation lacks specific reference to
the code you are using, and again, to what you are referring to (will you
learn to quote?). However, reviewing your code, it is obvious to me that
it (still) has a number of flaws.

- The underlying HTML code is not Valid. You cannot expect client-side
script code to work on not Valid markup, as you cannot expect a house
to stand on quicksand.

<URL:http://validator.w3.or g/check?uri=http://electrician.com/calculators/wireocpd_ver_1. html>

- The script is quite large. For HTTP request efficiency, large resources
should be splitted into smaller chunks. This means the script it should
be moved to an external script resource, e.g. program.js, which should be
included in the HTML document with

<script type="text/javascript" src="program.js "></script>

See also:
<URL:http://www.websiteopti mization.com/services/analyze/wso.php?url=htt p://electrician.com/calculators/wireocpd_ver_1. html>

- ECMAScript implementations provide a boolean type, with predefined
values of `true' and `false'. It is quite inefficient and error-prone
(unrecognized typos!) to use the string values "true"/"True" and
"false"/"False" instead.

- for (var i = 0; i <= form.aN.length; i++)
{
if (form.aN[i].selected)
{
ay =(form.aN[i].value);
break;
}
}

is syntactically correct, but semantically wrong, as it loops also for
form.aN[form.aN.length], which does not exist because the collection's
index is zero-based. Using

for (var i = 0; i < form.aN.length; i++)

instead, solves this problem. However, it would be still inefficient
(because of repeated deep lookup) and error-prone (because of proprietary
referencing). Therefore, it should be

for (var i = 0, len = form.elements['aN'].options.length ; i < len; i++)

Because the reference `form.elements' is used more than one time, it
should be assigned to a local variable once and that variable should
be used instead:

var es = form.elements, o = es['aN'].options;

for (var i = 0, len = o.length; i < len; i++)

But "aN" refers to one single select element that does not have the
"multiple" attribute. Therefore, it should be simply

ay = o[o.selectedIndex].value;

_without_ any unnecessary loop. You will also observe here that the
parentheses in

ay =(form.aN[i].value);

were redundant. Since you have been using obfuscation (which I recommend
against) to make the code as short as possible, you should endeavour not
to include any unnecessary code.

- au = eval(form.S[i].value);

is nonsense. The global eval() method merely evaluates its argument.
Unless its argument is a _string_ value that contains an arithmetic
expression, eval() is entirely redundant, inefficient, and error-prone.

While "S" refers to a `select' element in your HTML code and the `value'
property of HTMLSelectEleme nt objects should not be relied upon (use
selectRef.optio ns[selectRef.selec tedIndex] instead), the value of
that property in your case could be either (e.g. for the first item)
"0" or "21-25 (70-77F)".

Assuming it would be "0", being the value of the `value' property of the
respective HTMLOptionEleme nt object as specified in W3C DOM Level 2 HTML,

+es['S'][i]

or even

parseInt(es['S'][i], 10)

would be more efficient.

<URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-59351919>

Assuming that it would be instead "21-25 (70-77F)" as IIRC known from
some DOMs, eval(form.S[i].value) or its standards-compliant reference
equivalent would result in a syntax error.

Therefore the loop should be

for (var i = 0, o = es['S'].options, len = o.length; i < len; i++)

and it should be either

// allows for interpretation of 0x... as hexadecimal value
au = +o[i].value;

or

// parses 0x... as 0
au = parseInt(o[i].value, 10);

However, no loop is necessary at all here, too:

au = parseInt(o[o.selectedIndex].value, 10);

- for (var n = 0; n <= form.aY.length; n++)
{
if (form.aY[n].checked)
{
aB =(form.aY[n].value);
break;
}
}

is different from the above insofar it refers to a group of radiobuttons
with the same name, and not a `select' element. Therefore, the loop is
necessary here, indeed. However,

var aRadio = es['aY'];
for (var n = 0, len = aRadio.length; n < len; n++)
{
if (aRadio[n].checked)
{
aB = aRadio[n].value;
break;
}
}

is still better. (You will observe that the iterator variable and the
`len' variable can be reused. To avoid repeated declaration, you should
declare them locally before the `for' statements only once, and only
[re-]initialize them in each `for' statement. Certainly you do not need
two iterator variables `i' and `n' if the corresponding loops are
independent.)

You should consider using a method (function) that returns the value of
the selected radiobutton in a group. IIRC such a method can be found in
the newsgroup's FAQ, for example.

- As you will probably have guessed after having read the above,

bx =(eval((1.25 *(form.ab.value )))) +(eval(form.aS. value));

is utter nonsense, really.

- If you use boolean values as suggested,

if (ax == "True")

could be simplified to

if (ax)

and

if ((as == "False") &&(G == "False"))

could be simplified to

if (!as && !G)

and so on. (Whereas I recommend to avoid using identifiers starting with
a capital letter if they does not refer to a constructor or a factory;
just to avoid confusion, and to make source code easier readable.)

- ISTM other flaws/errors in your code include merely repetitions of the
flaws/errors that are described above.
HTH

PointedEars
Mar 5 '06 #5
I don't really try to meet the W3.org standards. 98 per cent of the
visitors to my site use IE5.0+. I stopped trying to be compatible with
Netscape, Opera, and Firefox long ago. I used to spend about 30 per
cent of my time on compatibility issues, but now have the attitude that
if the other browsers can't meet MS standards, then too bad. MS is
more of a standard setter than W3.org. Also, most users of my site
have high speed connections so I don't worry about large file sizes. I
have one popular calculator that is 85k right in the web page and I
have not had one single complaint in six years. Besides, js files are
too hard to edit! I suppose I am not in line with academia, but then
I taught myself what I know, and speak from experience. I use
JavaScript because of the ease of use, but more than that, for the
portability. Write it, upload it, and it is available. And as far as
compact code like you suggest, I don't worry about that either. Let
the machines hum and do all the work, they are made for it.
So I am a sloppy programmer, but my site makes money. I would get an F
in your class, but I am not worried about grades any more either. Next
month I start drawing social security.

Mar 5 '06 #6

<el*********@el ectrician.com> wrote in message
news:11******** **************@ v46g2000cwv.goo glegroups.com.. .
While running a program that exceeds the array limits it issues an
alert. I want to then stop the program after filling in the output
boxes with blanks. How do you stop the program?
I have worked on this for days and tried searching the net, but have
found nothing.


I put the whole thing in a function and do a return to exit.
Mar 5 '06 #7
el*********@ele ctrician.com wrote:
[no quote, lame excuses about error-prone inefficient code]


It is clear to me now that I have wasted my time on you. FOAD.
PointedEars
Mar 5 '06 #8
Perhaps you have learned something from my experience. Let's hope so.
Too many nit pickers are not familiar with real world experiences. I
am a hard knots laborer, electrician, with a degree in Mathematics that
applies production lessons from real work in the electrical trade to
programming. Something that I think is unique and beneficial to
academia types.

Mar 5 '06 #9
> While running a program that exceeds the array limits it issues an
alert. I want to then stop the program after filling in the output
boxes with blanks. How do you stop the program?
I have worked on this for days and tried searching the net, but have
found nothing.


<<I put the whole thing in a function and do a return to exit.>>
Yes. that works, but when the program is very complicated and long it
makes it kind of messy with those brackets about 2000 lines apart. The
program that I have written has taken 10 weeks over the last 10 years
and is very complicated. It applies complex linear programming models
with many exceptions.

Mar 5 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2045
by: Eric Osman | last post by:
My javascript program has reason to want to stop. For example, function A has 5 lines, the second of which calls function B, which has 5 lines, the first of which calls function C. But function C discovers that something is very wrong so it does an "alert" saying something like Sorry, couldn't make the necessary connection
2
4004
by: Martyn Fewtrell | last post by:
Dear All I have a Windows 2003 Server with IIS6 where the validation controls on ASP.Net pages no longer work. I believe it to be specific to the server as if I create an ASP.Net page on the IIS Server of my Workstation (Win XP) with a text box, button and required field validator, this works fine. If I create the same page on the IIS6 Windows 2003 Server the validation control doesn't stop the post. I've tried different browsers and...
8
2051
by: Richard Maher | last post by:
Hi, I am in a mouseup event for button A and I'd like to disable=false button B before starting some work. Is there anyway that an event for button B can then fire before my event processing for button A's mouseup has completed? I beleive event processing to be single-threaded for good reason but I need a "stop" button and it's no good if it doesn't do anything until the other processing has finished :-)
1
3587
by: =?Utf-8?B?S2Vubnk=?= | last post by:
I have one bat file that contains a command to startup Java Program. Then, I would like to create a cluster job to call the bat file. In case of one computer is down, another computer can also call the bat file and startup my Java Program. For this purpose, I have tried to place the bat file into share drive of two computers which are cluster machine. Also, I used Generic Application to create a job to call my bat file and this job is...
2
4307
by: mark4asp | last post by:
Can I force the client to stop caching old stylesheets and javascript? In my dynamic web-site, I need to force the client to stop caching old versions of my stylesheets and javascript. Can I do this by including a querystring with the url with each external stylesheet and script file declaration? For example: <link type="text/css" rel="stylesheet" href="../images/menu.css?
8
12619
praclarush
by: praclarush | last post by:
Ok, I'm new to JavaScript and I'm taking a class for it the assignment in it I'm supposed to create edit a pre-made page to display a marquee that automatically scrolls for the user, as well as give an option to start, stop and reset the marquee. Now I have most of this done already, what I'm having problems with is that when i start the marquee it moves to the right, but i need to have it move from the bottom, upwards. heres my code (I'm not...
8
4406
by: Harati | last post by:
I prepared my own player using php For this ,i want code for play(),pause(),stop(). I tried a lot with player.controls.play() but no use
0
3284
by: =?Utf-8?B?am1hZ2FyYW0=?= | last post by:
My program needs to do X when someone 'starts using' their Windows user account, and it should do Y when they 'stop using' their Windows user account. By 'starts using' I mean they log on, unlock the desktop, resume from hibernate/sleep, or resume a session that was paused via Switch User. By 'stop using' I mean they lock the desktop, initiate a hibernate/sleep , or choose Switch User while logged on. For context, the program is a parental...
4
2095
by: Rajneesh Chellapilla | last post by:
I wrote this program. Its kinda of strange when I make a reset function reset(){c=0} its doest reset the setTimeout. However if I directly pass c=0 to the onclick button it does reset the timer. What is the logic of this? Here is the program: <html> <head> <script type="text/javascript"> var c=0; var t; function timedCount()
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10050
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9999
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.