By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,384 Members | 1,886 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,384 IT Pros & Developers. It's quick & easy.

else if statements not working! =(

P: n/a
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!

Sep 1 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a

Pr********@gmail.com написав:
----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...

Sep 1 '06 #2

P: n/a
You're awesome <3

Sep 1 '06 #3

P: n/a
JRS: In article <11**********************@i3g2000cwc.googlegroups. com>,
dated Fri, 1 Sep 2006 04:53:10 remote, seen in
news:comp.lang.javascript, Pr********@gmail.com 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.
--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 1 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.