Re: Switch() Statement Not Working




rdavis7408@xxxxxxxxx wrote:
> <script language="JavaScript">

The language attribute is deprecated, use the type attribute instead:

<script type = "text/javascript">

> b=this.form.ppg.value

This statement is error-prone. Instead give your form a name and
access its elements in the following fashion:

var b = document.forms["formName"].elements["ppg"].value;

> switch(b)
> {
> Case >=1.25 && <=1.30:
> this.form.dlnt.value=.01;
> Case >=1.31 && <=1.369:
> this.form.dlnt.value=.02;
> Case >=1.37 && <=1.429:
> this.form.dlnt.value=.03;
> default:
> this.form.dlnt.value=.99
>
> }

1. It is not 'Case', but should be 'case' with a lowercase C.
2. You should have a 'break' after one or more cases. And a 'break'
after the default case.
3. The switch construct does not deal with a range of values. You
should instead use if...else statements instead.

var dintVal = .99;

if(b >= 1.25 && b <= 1.3)
{
dintVal = .01
}
else if(b >= 1.31 && b <= 1.369)
{
dintVal = .02
}
else if(b >= 1.37 && b <= 1.429)
{
dintVal = .03;
}

document.forms["formName"].elements["dInt"].value = dintVal;

.



Relevant Pages

  • Re: How come Ada isnt more popular?
    ... Every programming language isbe error-prone at different levels, ... Java is more error-prone than Ada ...
    (comp.lang.ada)
  • Re: How come Ada isnt more popular?
    ... The question is how error-prone a language might be. ... Ada is at the end of the scale for less error-prone ... A more detailed continuum could be developed that covers more languages. ...
    (comp.lang.ada)
  • Re: best method to perform operations on word lists
    ... current purpose it'll do the trick but any suggestion for optimization ... my $prev = 'nonesuch584685542256RANOM58544'; ... This didn't modify the list. ... hence my thoughts about language files. ...
    (comp.lang.perl.misc)
  • Re: How come Ada isnt more popular?
    ... who chooses to develop software in a language that is error-prone would expect ... But I think that "they" don't expect a software system that is error ... contributing to the overall cost of a project. ...
    (comp.lang.ada)
  • Re: Uncle Scrooge?
    ... (Is there any name that isn't the slang word for penis in some language ... Prev by Date: ...
    (alt.usage.english)