Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Simple Javascript issue

Posted on 2014-04-10
4
Medium Priority
?
175 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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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

879 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