Solved

Simple Javascript issue

Posted on 2014-04-10
4
164 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
  • 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now