Solved

Simple Javascript issue

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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 …
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…

770 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