[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 790
  • Last Modified:

Opera onclick defect in JS?

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

0
technoparkcorp
Asked:
technoparkcorp
2 Solutions
 
agriesserCommented:
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

0
 
fsze88Commented:
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

0
 
technoparkcorpAuthor 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

0
 
fsze88Commented:
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

0
 
Michel PlungjanIT ExpertCommented:
Can you show the JS file and the html you ACTUALLY use?

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

// -->
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now