We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Opera onclick defect in JS?

technoparkcorp
on
Medium Priority
799 Views
Last Modified: 2012-05-06
Why this code doesn't work in Opera? And it works in all other browsers (IE, FF)

When the user clicks the button nothing happens. Why so?
<form>
<input id="continue" type="button" value="Continue" onclick="ToContinue();" />
</form>

Open in new window

Comment
Watch Question

Top Expert 2008
Commented:
Sometimes browsers (IE behaves the same) need a "return false" after the onclick event (see codesnippet below).

The function "ToContinue()" is defined properly in the active context? I don't know opera very well, but does it have some Javascript error debugging utility like Firefox has?


<form>
<input id="continue" type="button" value="Continue" onclick="ToContinue(); return false;" />
</form>

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
CERTIFIED EXPERT
Commented:
I tested on ie6,ff3,opera,safari
they are works fine...
still have problem? may be cause of your js function ToContinue().....
<form>
<input id="continue" type="button" value="Continue" onclick="alert('abc'); " />
</form>

Open in new window

Author

Commented:
This snippet works fine in all browsers.

When I move the function to the script file, it doesn't work. What's wrong?
<html><body>
<form>
<input id="continue" type="button" value="Continue" onclick="ToContinue(); return false;" />
</form>
<span id="test">old</span>
<script type='text/javascript'>
<!--
function ToContinue () {
	document.getElementById ('test').innerHTML = 'new';
}
-->
</script>
</body></html>

Open in new window

CERTIFIED EXPERT

Commented:
why? What's wrong?
there a space between getElementById ('test')
                                                      ^



 
<html><body>
<form>
<input id="continue" type="button" value="Continue" onclick="ToContinue(); return false;" />
</form>
<span id="test">old</span>
<script type='text/javascript'>
<!--
function ToContinue () {
        document.getElementById('test').innerHTML = 'new';
}
-->
</script>
</body></html>

Open in new window

Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
Can you show the JS file and the html you ACTUALLY use?

Also you should comment out inline html comments in JS
Like this:

// -->
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.