Hi,
I'd say your problem is the eval. There's no reason why you should be using eval to concatenate a string and number.
var space = "space" + ansnum; will suffice.
There is a better solution, though, to the way you are going about your script. Why not put all the relevant answers in the html itself and just hide it, through css, until they click the anchor. This way you can have all the content in an easy to index format, and have it searchable by a crawler. If you put the questions and answers in a defintion list, it will also increase the page's semantic relevance in the eyes of the search bots.
The way you are going about it, you will have to put all your answers in a javascript array ... not a very attractive solution.
Anyway, here's an example of what I'm talking about.
Code:
<html>
<head>
<style type="text/css">
dl {
font: 80% verdana, sans-serif;
}
dt {
font-weight: bold;
}
dd {
display: none;
}
.on {
display: block;
}
.off {
display: none;
}
</style>
<script type="text/javascript">
function display(obj)
{
var el = document.getElementById(obj);
if(el.className == '' || el.className == 'off')
el.className = 'on';
else el.className = 'off';
}
</script>
</head>
<body>
<dl>
<dt><a href="#ans1" onclick="display('a1'); return false;">This is question number 1?</a></dt>
<a name="ans1"></a>
<dd id="a1">And the answer is... And the answer is... And the answer is...
And the answer is... And the answer is... And the answer is...
And the answer is... And the answer is... And the answer is... </dd>
</dl>
<dl>
<dt><a href="#ans2" onclick="display('a2'); return false;">This is question number 2?</a></dt>
<a name="ans2"></a>
<dd id="a2">And the answer is... And the answer is... And the answer is...
And the answer is... And the answer is... And the answer is...
And the answer is... And the answer is... And the answer is... </dd>
</dl>
<dl>
<dt><a href="#ans3" onclick="display('a3'); return false;">This is question number 3?</a></dt>
<a name="ans3"></a>
<dd id="a3">And the answer is... And the answer is... And the answer is...
And the answer is... And the answer is... And the answer is...
And the answer is... And the answer is... And the answer is... </dd>
</dl>
</body>
</html>
This solution doesn't take into account if the user has ns4 or ie4, but you can put the relevant code to detect them if you wish. The amount of users still using these browsers isn't worth it imo. When you think about it, your already blocking 14% of the surfing public, the percentage of people that have javascript disabled, from even being able to use your page at all. Why even bother detecting if the other 1% are using antiquated browsers?
-xDev
Bookmarks