Basic Javascript Error

I get an error when trying to call a function upon button click

Page 1 of 1

7 Replies - 992 Views - Last Post: 17 October 2009 - 02:34 AM

#1 nadunx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 13-September 09

Basic Javascript Error

Post icon  Posted 16 October 2009 - 08:29 AM

I wrote a simple javascript function but I cant get it to work upon a button click event because it keeps telling me that "object is expected" ? could you please identify where the error is ?

heres my code

<html>
<head>
<title>Test</title>
	<script type="text/Javascript" language="Javascript">		
		function output()
		{
			alert("Hello world");
		}
	</script>
<head>
<body>
	<input type="button" name="btnSubmit" value="submit" onclick="output();" />
	<input type=button onclick="output();"> 
</body>
</html>



it keeps indicating me that there is an error when calling the method on button click.. I've tried to figure it out but yet Im stuck with it .

Is This A Good Question/Topic? 0
  • +

Replies To: Basic Javascript Error

#2 ecuscotty  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 40
  • Joined: 14-October 09

Re: Basic Javascript Error

Posted 16 October 2009 - 09:17 AM

Hello,

Your code seems to work ok for me. The only thing I see that's wrong is your head tag is not closed properly, but that shouldn't effect your javascript. And technically your buttons should be in a form, but again, shouldn't effect your js.

What browser are you using? Could you have an old version of the page cached in your Browser?

Regards
Was This Post Helpful? 0
  • +
  • -

#3 nadunx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 13-September 09

Re: Basic Javascript Error

Posted 16 October 2009 - 09:23 AM

I tested it with the head tag properly closed both on IE 8 and FF 3 . Firefox doesnot react when buttons are clicked.. IE displayes its inbuit javascrip debugger when clicked on the buttons. It highlights the function name in the onclick attribute on buttons and says "Object expected" . Im using windows 7 by the way.

Edit : did you say that the code worked fine on your computer ? pls let me know so I can get an idea :)

This post has been edited by nadunx: 16 October 2009 - 09:24 AM

Was This Post Helpful? 0
  • +
  • -

#4 Nykc  Icon User is offline

  • Gentleman of Leisure
  • member icon

Reputation: 731
  • View blog
  • Posts: 8,644
  • Joined: 14-September 07

Re: Basic Javascript Error

Posted 16 October 2009 - 09:28 AM

I too also executed this code fine in FF3.5
Was This Post Helpful? 0
  • +
  • -

#5 Jhin  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 8
  • View blog
  • Posts: 257
  • Joined: 06-July 05

Re: Basic Javascript Error

Posted 16 October 2009 - 09:31 AM

It worked on mine here at work:

On both IE 8.0 and Google Chrome 3 (WinXP SP3)
Was This Post Helpful? 0
  • +
  • -

#6 nadunx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 13-September 09

Re: Basic Javascript Error

Posted 16 October 2009 - 09:35 AM

thanks for the replies:)
I'm still not able to run this code on my computer . could it be because of some restrictions on windows 7 ? ( is it even possible ? )
anyway so the error is with my computer or the softwares here I have, I'll try looking into it rather than trying to find an error on a working code :)
Was This Post Helpful? 0
  • +
  • -

#7 ecuscotty  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 40
  • Joined: 14-October 09

Re: Basic Javascript Error

Posted 16 October 2009 - 11:02 AM

It worked for me in IE and Firefox, but I too am on Win XP SP3. If you find that this is a Windows 7 issue could you please post back here and let us know. I was going to upgrade to Win 7 this weekend, maybe I'll wait...

Thanks
Was This Post Helpful? 0
  • +
  • -

#8 nadunx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 13-September 09

Re: Basic Javascript Error

Posted 17 October 2009 - 02:34 AM

I found the issue I had and its nothing to do with windows 7 so you can upgrade to it safely ( I love windows 7 too :P )

there were several functions in the original file with the one I put here and I noticed that if you have even a single error in the javascript code , it fails to run completely. there was an error in one function ( in try-catch block I forgot to pass the parameter to the catch block : catch(ex) ) that was the error I had and now it all works :)

could you tell me why javascript fails when there is an error in a function although the function is never invoked. kinda strange though ..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1