Re: looking for a short IF statement example.
- From: <cheers>
- Date: Mon, 16 May 2005 22:53:30 +0100
If not IF or iF or if
Else not ELSE or ElSe
correct ?
ok but still the If and Else statements does not work.
also i changed the all of the If and Else statements for a single
alert("a")
this works and the alert box shows, i have also added this alert("a") like
so
a=1;
If (a=1);
{
alert("a")
}
but the alert box does not show
i have also tried adding var a=1 in place of a=1 to assign the variable.
but this also does not work.
the alert box does not show.
this has got to be something simple, i think we have gone through all but
the correct way to do this.
again, just to make sure you know where these If Else statements are
going.
i have a file called myscripts.js this file starts...
function myscripts() {
...
...
the rest of the script works ok.
...
until it gets to the bottom before the script is terminated with the final }
where it has all that we have listed above. (the If and Else parts of the
script)
where are we going wrong.
Jason
"Steve Easton" <admin@xxxxxxxxxxxxx> wrote in message
news:uOhK2mlWFHA.2796@xxxxxxxxxxxxxxxxxxxxxxx
> Why are you using eval??
>
> have you tried just
>
> If (a=1) {
> document.write("a=1");
> }
> Else
> {
> document.write("a does not =1");
> }
> If (b=1) {
> document.write("b=2");
> }
> Else
> {
> document.write("b does not=2");
> }
>
> Also remember that javascript is CaSe sensative.
>
> --
> Steve Easton
> Microsoft MVP FrontPage
> 95isalive
> This site is best viewed............
> .......................with a computer
>
> <cheers> wrote in message news:O4pyEkkWFHA.1468@xxxxxxxxxxxxxxxxxxxxxxx
>> looking at my example i realiase it was not correct.
>>
>> this is a better example of how i am wanting to use the If and ELSE IF
>> statements
>> but the ELSE IF part does not work. the first IF statement work the ELSE
>> IF
>> does not.
>> also if i have the ELSE IF part replaced with another IF line i.e
>>
>> i know this is not formed right but you get the jist.
>> if this=1 then print 'this =1'
>> if this=0 then print 'this is not 1'
>> ...
>> ...
>> ...
>>
>> without the use of the ELSE IF it still does not work.
>>
>> below is the example of what i am attempting to do.
>>
>>
>> the .js file that is called in one of my iframes.
>>
>> function nameoffunction() {
>> a=1;
>> b=2;
>> c=3;
>>
>>
>>
>> if (eval(a)=1) {
>> document.write("a=1");
>> }
>> else
>> {
>> document.write("a does not =1");
>> }
>>
>>
>>
>> if (eval(b)=1) {
>> document.write("b=2");
>> }
>> else
>> {
>> document.write("b does not=2");
>> }
>>
>>
>>
>> if (eval(c)=1) {
>> document.write("c=3");
>> }
>> else
>> {
>> document.write("c does not=3");
>> }
>>
>>
>>
>> }
>>
>>
>>
>>
>>
>>
>> i have looked on the internet for examples of IF ... ELSE IF
>> statements.
>>
>> they all take the form...
>>
>> IF (morethanzero=1) {
>> document.write("more than zero");
>> }
>> ELSE {
>> document.write("not more than zero");
>> }
>>
>>
>> so why do all of mine not work
>>
>>
>>
>>
>>
>>
>> "Steve Easton" <admin@xxxxxxxxxxxxx> wrote in message
>> news:%231ZTa6jWFHA.584@xxxxxxxxxxxxxxxxxxxxxxx
>> > For the subsequent If statements after the first IF you should use
>> > Else If
>> >
>> >
>> > --
>> > Steve Easton
>> > Microsoft MVP FrontPage
>> > 95isalive
>> > This site is best viewed..................
>> > ..............................with a computer
>> > <cheers> wrote in message news:ehllmHjWFHA.2348@xxxxxxxxxxxxxxxxxxxxxxx
>> >> i would like to know how to insert an IF statement within a function.
>> >> below
>> >> is what i believe was right. but i am wrong as the IF statement does
>> >> not
>> >> run.
>> >> if i take out the ELSE part of the statement i am half way there, but
>> >> i
>> >> need
>> >> the ELSE part too.
>> >>
>> >> i know that there is an easier way to show what the total is, by just
>> >> displaying the total, but this would not show me how the if statement
>> >> works.
>> >> thanks
>> >>
>> >> this is not my .JS file it is an example that would hopefully help me
>> >> understand how to use the IF and ELSE statements within a .JS file.
>> >>
>> >> lets say my .JS file takes the form.
>> >>
>> >> function nameoffunction() {
>> >> a=1
>> >> b=2
>> >> c=3
>> >> total=eval(a+b+c)
>> >>
>> >> if (eval(total)) =1
>> >> {
>> >> document.write("the total is 1")
>> >> }
>> >> else
>> >> {
>> >> document.write("the total was not 1")
>> >> }
>> >>
>> >> if (eval(total)) =1
>> >> {
>> >> document.write("the total is 2")
>> >> }
>> >> else
>> >> {
>> >> document.write("the total was not 2")
>> >> }
>> >>
>> >> if (eval(total)) =1
>> >> {
>> >> document.write("the total is 3")
>> >> }
>> >> else
>> >> {
>> >> document.write("the total was not 3")
>> >> }
>> >>
>> >> }
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> "Kevin Spencer" <kevin@xxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>> >> news:egL1MxiWFHA.1404@xxxxxxxxxxxxxxxxxxxxxxx
>> >> >> i am trying to have an IF statment in side a script function.
>> >> >
>> >> > Not exactly. I'm not sure exactly WHAT you're trying to do, but what
>> >> > you
>> >> > think you're trying to do is a HOW, not a WHAT. I believe your HOW
>> >> > is
>> >> > in
>> >> > error, so if you could tell us in detail what you want your function
>> >> > to
>> >> > do, I can supply a solution. Note that "when it is called it
>> >> > calculates
>> >> > a
>> >> > sum" is not specific enough. A sum, for example, is the product of
>> >> > adding
>> >> > numbers together. "depending on the answer it will print certain
>> >> > words"
>> >> > is
>> >> > not specific enough. Since your code is in error, I can' tell WHAT
>> >> > words
>> >> > it wants to print. An example of a good explanation of your business
>> >> > requirement might be something like the following:
>> >> >
>> >> > "I have a text field which only accepts numbers, and will not
>> >> > validate
>> >> > until there is a value in the text field. The name of the text field
>> >> > is
>> >> > 'Avocado.' I want to use the number input in that field. When the
>> >> > text
>> >> > field loses focus (not when the form is submitted, of course), I
>> >> > want
>> >> > to
>> >> > display the number in a div. The div is on the same page, and has an
>> >> > id
>> >> > of
>> >> > 'b_Avocado'"
>> >> >
>> >> > This is probably not exactly what you are tryiing to do, but notice
>> >> > that
>> >> > it leaves little room for the imagination. I could write a function
>> >> > that
>> >> > performs this in a few minutes, and would be glad to tell you how
>> >> > to,
>> >> > if
>> >> > you could give just as good an explanation of your requirement.
>> >> >
>> >> > --
>> >> > HTH,
>> >> >
>> >> > Kevin Spencer
>> >> > Microsoft MVP
>> >> > .Net Developer
>> >> > Sometimes you eat the elephant.
>> >> > Sometimes the elephant eats you.
>> >> >
>> >> > <cheers> wrote in message
>> >> > news:eI0ykohWFHA.1468@xxxxxxxxxxxxxxxxxxxxxxx
>> >> >> Please could someone tell me how i insert a IF statement within a
>> >> >> .JS
>> >> >> file
>> >> >>
>> >> >> i have a script file called myscript1.js
>> >> >>
>> >> >> when it is called it calculates a sum and depending on the answer
>> >> >> it
>> >> >> will
>> >> >> print certain words.
>> >> >>
>> >> >> i.e.
>> >> >>
>> >> >>
>> >> >> function Gettotal()
>> >> >> {
>> >> >>
>> >> >> var form = document.forms.selecteddata;
>> >> >>
>> >> >> if eval(form.Avocado.value)>0
>> >> >> {
>> >> >>
>> >> >> parent.orderlist.document.getElementById('b_Avocado').innerHTML
>> >> >> =
>> >> >> adddecimal(eval(form.Avocado.value*cAvocado));
>> >> >> }
>> >> >>
>> >> >> }
>> >> >>
>> >> >>
>> >> >>
>> >> >>
>> >> >>
>> >> >> if you are not sure what i mean, please ask for another example of
>> >> >> what i
>> >> >> am trying to do.
>> >> >>
>> >> >> i am trying to have an IF statment in side a script function.
>> >> >>
>> >> >> but the script does not run, if i take out the IF staement the rest
>> >> >> of
>> >> >> the script runs ok, but i need to have stuff printed in parts of
>> >> >> the
>> >> >> window if the sum is a certain number.
>> >> >>
>> >> >> Thank you
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >>
>> >>
>> >
>> >
>>
>>
>
>
.
- Follow-Ups:
- Re: looking for a short IF statement example.
- From: Ronx
- Re: looking for a short IF statement example.
- From: Ronx
- Re: looking for a short IF statement example.
- References:
- looking for a short IF statement example.
- From: cheers
- Re: looking for a short IF statement example.
- From: Kevin Spencer
- Re: looking for a short IF statement example.
- From: cheers
- Re: looking for a short IF statement example.
- From: Steve Easton
- Re: looking for a short IF statement example.
- From: cheers
- Re: looking for a short IF statement example.
- From: Steve Easton
- looking for a short IF statement example.
- Prev by Date: Re: View of Source in Explorer
- Next by Date: Re: looking for a short IF statement example.
- Previous by thread: Re: looking for a short IF statement example.
- Next by thread: Re: looking for a short IF statement example.
- Index(es):
Relevant Pages
|