473,394 Members | 1,640 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Javascript Error (Line: 1 Char: 1 Error: Object Expected Code: 0)

whatelyb
I am having trouble related to the attached coding.

I am trying to make the object "flight1pic" change depending on what is selected in the drop down menus "airline1" and "aircraft1".

My problem is when changing "airline1" it all works fine, but when changing "aircraft1" i get the error:

Line: 1
Char: 1
Error: Object Expected
Code: 0

Expand|Select|Wrap|Line Numbers
  1. function flightpicFunction(){
  2.     if(document.getElementById('airline1').value == "Qantaslink" && document.getElementById('aircraft1').value == "Boeing 717"){ document.getElementById('flight1pic').innerHTML = "<img src=../images/aircraft/QF_B717.jpg>"; }
  3.     if(document.getElementById('airline1').value == "Skywest" && document.getElementById('aircraft1').value == "Fokker 100"){ document.getElementById('flight1pic').innerHTML = "<img src=../images/aircraft/XR_F100.jpg>"; }
  4. }
  5.  
Can anyone tell me what i might be doing wrong?

Expand|Select|Wrap|Line Numbers
  1. <select size="1" onChange="flightpicFunction();" name="aircraft1" tabindex="3">
  2.   <option value="BAe 146">BAe 146</option>
  3.   <option value="Boeing 717">Boeing 717</option>
  4.   <option value="Boeing 737">Boeing 737</option>
  5.   <option value="Dash 8">Dash 8</option>
  6.   <option value="Embraer 120">Embraer 120</option>
  7.   <option value="Embraer 145">Embraer 145</option>
  8.   <option value="Embraer 170">Embraer 170</option>
  9.   <option value="Embraer 190">Embraer 190</option>
  10.   <option value="Fokker 100">Fokker 100</option>
  11.   <option value="Fokker 50">Fokker 50</option>
  12.   <option value="Other">Other</option>
  13. </select>
  14.  
Attached Files
File Type: txt error.txt (1.5 KB, 500 views)
May 18 '10 #1

✓ answered by whatelyb

Sorry to mess you around. The problem turned out to be my PHP coding.

The PHP coding I had set up changed which javascript function the dropdown menu called up, to one that didn't exist.

All works fine now. Thanks.

9 10130
Frinavale
9,735 Expert Mod 8TB
I've moved your question from the Java forum into the JavaScript forum where you will find more help with your JavaScript question.


Select HTML elements consist of a bunch of options.
It doesn't make sense to set a select HTML element's "value" property because it doesn't have a value....it has a bunch of options.

-Frinny
May 18 '10 #2
@Frinavale
Sorry, can you explain it to me in lamens (easy) terms? I'm good with PHP but I really haven't the slightest clue with Javascript.
May 19 '10 #3
I have tried replacing the code:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById('aircraft1').value
  2.  
with this code:
Expand|Select|Wrap|Line Numbers
  1. document.navform.aircraft1.options[document.navform.aircraft1.selectedIndex].value
  2.  
And I still get the same error. :(
May 19 '10 #4
Sorry to mess you around. The problem turned out to be my PHP coding.

The PHP coding I had set up changed which javascript function the dropdown menu called up, to one that didn't exist.

All works fine now. Thanks.
May 19 '10 #5
You are on the right track with selectedIndex.

try something like:

Expand|Select|Wrap|Line Numbers
  1. var dropdown = document.forms[0].aircraft1;
  2. var selection = dropdown[dropdown.selectedIndex].value;
  3.  
Here's a reference for more information:
http://www.w3schools.com/jsref/prop_...ectedindex.asp

And by the way, I highly recommend doing your JavaScript debugging in a different browser. Those Internet Explorer error messages just aren't that helpful. There is a handy plugin for Firefox called Firebug; and there are developer tools built in to the Chrome browser.

Happy coding!
May 19 '10 #6
I see you got it sorted out before I hit the "post reply" button! Glad to hear it.
May 19 '10 #7
Yeah thanx anyway "thesmithman" and also "Frinavale". I suppose the best diagnosis is a good night sleep. Was trying to figure it all out at 2am in the morning (before I relised what time it was.)
May 19 '10 #8
Frinavale
9,735 Expert Mod 8TB
Internet Explorer 8 comes with a debugger (hit F12).
If you like FireFox then download a plugin called FireBug.

-Frinny
May 19 '10 #9
Dormilich
8,658 Expert Mod 8TB
two things from my side.

your <select> does not have an ID, so trying to access it with getElementById() will only work in IE (given the name is unique, too).

second, a <select> indeed has a value property, which you can read and write.
May 19 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Erik-Jan Bakker | last post by:
Hello, I am stuck with a weird javascript problem.... ;-( Maybe it's somehting very simple, but I am really stuck in it, right now. What's the matter.... When place my website at a different...
1
by: Andrew Phillipo | last post by:
I have some code that works everywhere but IE5.0, including IE5.5. Here is a snippet of where the code seems to go wrong: Location.prototype.change = function(current) { this.current = current;...
1
by: Itzik | last post by:
Hi i have any error in my function can i get only error line Thanks
11
by: westplastic | last post by:
This one is driving me insane. The script works perfect on Firefox, but Internet Explorer keeps complaining about "Error Object Expected" and stuff like that. I've run it through Firefox's Java...
2
by: Jinx08 | last post by:
I am probably an itermediate user when it comes to flash however I am at a loss with this problem. I have posted numerous flash files to the internet and never had this problem however the key there...
7
by: cfps.Christian | last post by:
I've written a .js file and put the script in my usercontrol: <script src="myscript.js" /> Added the attributes to my controls: lbl.Attributes.Add("onclick", "DoWork(this);") - Also tried...
2
by: tridirk | last post by:
Hi; I am getting a Objceted Expected Error on my forum site. I can't find what is wrong? Line: Char: Error: Object expected Code:0 the site is My SMF Forum
2
by: Joe Gutierrez | last post by:
Please help, I'm getting this error, Object expected, Code: 0 in Internet Explorer (not in Firefox, though). Here is the link: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.