<a href="javascript:expand()"> and <a href="#" onclick="javascript:expand()">
What's the difference? I know the href="#" is the more standard method now a days to do it. My issue is that I have a standard dropdown menu that expand/collapse when user clicks on toggle. If I do href="#" for the code below, whenever someone clicks on the expand control, the page always scroll right back to the top that is not acceptable from a user friendly point. If I use href="javascript:expand()" when user clicks on expand control, the page doesn't move and all is going fine. So will there be any issue if I just use href="javascript:expand()" instead? or how do I resolve the href="#" so the page doesn't scroll back to the top whenever user clicks expand.
Thanks.
Code:
<html>
<head>
<title> tabletest </title>
<script>
function expand(sec)
{
thisSec = eval('e' + sec);
if (thisSec != null){
if (thisSec.length){
if (thisSec[0].style.display != 'none'){
for (var i=0;i<thisSec.length;i++) {thisSec[i].style.display = 'none'}
}
else{
for (var i=0;i<thisSec.length;i++) {thisSec[i].style.display = 'inline'}
}
}
else{
if (thisSec.style.display != 'none') {thisSec.style.display = 'none'}
else{thisSec.style.display = 'inline'}
}
}
}
</script>
</head>
<body>
<table cellpadding="0" cellspacing="0" width="950" border="0">
<tr>
<td>col1</td>
<td align="right">col2</td>
<td align="right">col3</td>
<td align="right">col4</td>
<td align="right">col5</td>
<td align="right">col6</td>
</tr>
<tr>
<td><a href="javascript:expand(0)"> toggle abbbccaaaaa</a></td>
<td align="right"> 75</td>
<td align="right"> 12</td>
<td align="right"> 325</td>
<td align="right"> 115</td>
<td align="right"> 105</td>
</tr>
<tr id="e0" style="display:none">
<td colspan="99">
<table border="0">
<tr><td>column1</td><td>column2</td></tr>
<tr><td><img src="space.gif" height="1" width="100%"></td></tr>
<tr><td>1</td><td>abadd</td></tr>
<tr><td><img src="space.gif" height="1" width="100%"></td></tr>
<tr><td>5</td><td>cddad</td></tr>
<tr><td><img src="space.gif" height="1" width="100%"></td></tr>
<tr><td>30</td><td>asfddf</td></tr>
<tr><td><img src="space.gif" height="1" width="100%"></td></tr>
</table>
</td>
</tr>
<tr>
<td><a href="javascript:expand(1)">toggle abbbccaaaaa</a></td>
<td align="right"> 75</td>
<td align="right"> 12</td>
<td align="right"> 325</td>
<td align="right"> 115</td>
<td align="right"> 105</td>
</tr>
<tr id="e1" style="display:none">
<td colspan="99">
<table border="0">
<tr><td>column1</td><td>column2</td></tr>
<tr><td><img src="space.gif" height="1" width="100%"></td></tr>
<tr><td>1</td><td>abadd</td></tr>
<tr><td><img src="space.gif" height="1" width="100%"></td></tr>
<tr><td>5</td><td>cddad</td></tr>
<tr><td><img src="space.gif" height="1" width="100%"></td></tr>
<tr><td>30</td><td>asfddf</td></tr>
<tr><td><img src="space.gif" height="1" width="100%"></td></tr>
</table>
</td>
</tr>
</table>
</body>
</html>
Bookmarks