Solved

Simple Javascript issue

Posted on 2014-04-10
4
171 Views
Last Modified: 2014-04-10
Hi all - I must be overtired or losing my mind lol.  I'm trying to get the following to work but it's not and I can't seem to figure out why?!

<script type="text/javascript">
function totalflighttime() {
    if (document.getElementById("totalflighttime").value == "1"){
        document.getElementById("atotalflighttime").innerHTML = "10";
    }     
    elseif (document.getElementById("totalflighttime").value == "2") {
        document.getElementById("atotalflighttime").innerHTML = "5";
    }
    elseif (document.getElementById("totalflighttime").value == "3") {
        document.getElementById("atotalflighttime").innerHTML = "3";
    }
    elseif (document.getElementById("totalflighttime").value == "4") {
        document.getElementById("atotalflighttime").innerHTML = "2";
    }
}
</script>

	<td><select name="totalflighttime" id="totalflighttime" onChange="totalflighttime();"><option value="">:: Select ::</option><option value="1">100-300hrs</option><option value="2">300-500hrs</option><option value="3">500-750hrs</option><option value="4">750-1000+hrs</option></select></td>

   <td><div id="atotalflighttime"></div>&nbsp;</td></tr>

Open in new window

0
Comment
Question by:zack4x4
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 39991601
Sounds dumb but try the function with single quotes instead of double quotes.

<script type='text/javascript'>
function totalflighttime() {
    if (document.getElementById('totalflighttime').value == '1'){
        document.getElementById('atotalflighttime').innerHTML = '10';
    }     
    elseif (document.getElementById('totalflighttime').value == '2') {
        document.getElementById('atotalflighttime').innerHTML = '5';
    }
    elseif (document.getElementById('totalflighttime').value == '3') {
        document.getElementById('atotalflighttime').innerHTML = '3';
    }
    elseif (document.getElementById('totalflighttime').value == '4') {
        document.getElementById('atotalflighttime').innerHTML = '2';
    }
}
</script>

Open in new window

0
 
LVL 38

Accepted Solution

by:
Tom Beck earned 500 total points
ID: 39991633
Your

} elseif  ()

should be

} else if ().
0
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 39991647
Missed that :)
0
 
LVL 4

Author Closing Comment

by:zack4x4
ID: 39991660
Awesome thanks!
0

Featured Post

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question