(XHTML) Link with onClick, no refresh?

I've got a link like this:

<a href="javascript://" onClick="someFunction();">Link Text</a>

with a doctype of XHTML strict (e.g):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

My question is, whenever I click on this link, I don't want the page to refresh. I just want it to call the javascript function, and do nothing else. I know that with html4 transitional the above link works fine. but with xhtml strict I can't get it to work with xhtml.

Any ideas greatly appreciated.

-Umbrae

LVL 5
umbraeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

amit_gCommented:
Add return false ...

<a href="#" onClick="someFunction();return false;">Link Text</a>
umbraeAuthor Commented:
Doesn't work, still refreshes the page.

Code tested like this:
<a href="#" onClick="showComment(); return false;"
class="rateCommentText" id="rateCommentText">CommentText</a>
umbraeAuthor Commented:
Also note, it only refreshes in IE. Firefox it works in.
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

amit_gCommented:
Show the function showComment()
umbraeAuthor Commented:
function showComment()
{
   document.getElementById('commentbox').style.display = 'block';
}

I know, one line function is odd. Has to be a function though, for other reasons.
amit_gCommented:
The combination

function showComment()
{
   document.getElementById('commentbox').style.display = 'block';
}

<a href="#" onClick="showComment(); return false;" class="rateCommentText" id="rateCommentText">CommentText</a>

cannot cause the refresh. There must be something else. Take a look at body onload and/or window.onload. Search for setInterval, setTimeout or meta refresh.
umbraeAuthor Commented:
There is no onLoads, setIntervals, or setTimeouts, and meta refresh doesn't come into it either. (furthermore, those would not occur -when- I clicked on the link, they'd occur on their own)
amit_gCommented:
Well then we need to see the complete code. If it is on the net that would be even better.
umbraeAuthor Commented:
http://www.carthage.edu/testrate.cfm

It's on the bottom, when you click on "Comment on this Page", it refreshes the page in IE 6
amit_gCommented:
There is a reload in menu_ie5.js. This is called when the browser is resized. When you show the comment box, the space used is increased and IE raises onresize event.

if(allowRESIZE==true){window.location.reload();}

I don't think you can change the menu script but if there is a parameter that allows you to stop the browser resize functionality, use that. If not, change the function to...

function showComment()
{
      document.getElementById('rateCommentBox').style.visibility='visible';
}

and change the span to

<span id="rateCommentBox" class="rateCommentbox" style="visibility: block;visibility: hidden">

This way even though the comment text box is not visible but it still has allocated space for it. Now showing the textbox doesn't change the allocated space and so the resize event is not fired. This doesn't look very good though. If that is a problew, we can try something else also like

            var eh_old; // Make sure to keep this out of every function.
            
            function showComment()
            {
                  eh_old = window.onresize;
                  window.onresize = new Function(";");
                  document.getElementById('rateCommentBox').style.display='block';
                  setTimeout("window.onresize = eh_old;", 100);
            }

and leave the span as it is now.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
umbraeAuthor Commented:
Giving the points to amit_g. Also increasing by 100 points, because he's done an exemplary job.
amit_gCommented:
Thanks :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development Software

From novice to tech pro — start learning today.