else if statements not working! =(

P

PrinceMhul

I have multiple functions that I am trying to get to work based on what
my textbox says. If the textbox says "1" then I want the function
"revealit1()" to be called. If it says 2, I want "revealit2()" to be
called. But it doesn't seem like it wants to work. Maybe I'm doing
something wrong, but I'm so new to javascript - I'm probably
overlooking something.

----start code----
function revealcontrol(){
var txt = document.getElementById('whatreveal');

if(txt='1'){revealit1()}
else if(txt='2'){revealit2()}
else if(txt='3'){revealit3()}

}
----end code----


The basis of what I'm trying to do can be seen at:
www.cnex.us/sandbox/demo.html
(so far my site only works in firefox...)
If you click one of the links, 1 - 2 - 3 - 4 - 5 etc, it calls it's
corrisponding revealit1() revealit2() etc function, which then reveals
pictures below. Then, the listbox that says "Foward" is which way I
want the characters to face when you select them. Right now, it has
onChange revealit1(), which takes the user BACK to LINK 1. What I want
to eventually do (the reason why I need the code) is set it so that
when you click the link "1", it sets a textbox to a certain text (or
even a listbox to a certain selected), and THEN when you go to change
the listbox that says "foward", it will just call the function that is
in the textbox that was preset in there.

So for instance. If you click link "1", it would set the textbox to
textbox1.value='1'
Then, if you change the listbox "Foward" to something else, it will
call "revealcontrol()" function which has the JS I posted above, with
else if statements such as "If textbox = 1 then call function1(), else
if textbox=2 then call function2(), etc etc"

Someone told me usenet was awesome and I'd get an awesome answer so
don't let me down! :D Thanks!
 
M

marss

(e-mail address removed) напиÑав:
----start code----
function revealcontrol(){
var txt = document.getElementById('whatreveal');

if(txt='1'){revealit1()}
else if(txt='2'){revealit2()}
else if(txt='3'){revealit3()}

}

(txt.value == '1') and so forth...
 
D

Dr John Stockton

JRS: In article <[email protected]>,
dated Fri, 1 Sep 2006 04:53:10 remote, seen in
news:comp.lang.javascript, (e-mail address removed) posted :
function revealcontrol(){
var txt = document.getElementById('whatreveal');

if(txt='1'){revealit1()}
else if(txt='2'){revealit2()}
else if(txt='3'){revealit3()}

}

or (partly tested)

function revealcontrol() {
[, revealit1, revealit2, revealit3]
[+document.getElementById('whatreveal').value]() } // <g>



It's a good idea to read the newsgroup and its FAQ.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top