Re: looking for a short IF statement example.

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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
>> >>
>> >>
>> >
>> >
>>
>>
>
>


.


Quantcast