Solved

Simple Javascript issue

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

828 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