Reputation: 1
I have written this javascript
<script type="text/javascript">
function toggle(user_id) {
e=document.getElementById('toggleUserinfo_'+user_id);
a=document.getElementById('displayUserinfo_'+user_id);
if (e.style.display=='block') {
e.style.display='none'; a.innerHTML='show';
} else {
e.style.display='block'; a.innerHTML='hide';
}
}
</script>
but its working fine on one page not working on other. The same file is used on both, any ideas?
Upvotes: 0
Views: 282
Reputation: 105029
It's highly likely that you don't have those two elements on the other page either.
toggleUserinfo_ID
toggleUserinfo_ID
ID being user_id.
When having Javascript problems, majority of web developers use Firefox with Firebug extension that alows you to set breakpoints and debug the whole javascript functionality of the page.
Set a breakpoint on the first lone of your toggle
function and see what's going on.
Upvotes: 0
Reputation: 726
The chance is that in the other page the elements don't exist for example the "toggleUserInfo_" and "displayUserInfo_", check to see whether they are available or not.
Another problem that I see is "e" and "a" both the variables are global( missing var keyword ) which is not good.
Upvotes: 1
Reputation:
did you try by putting debugger; and debugging the code
and also if possible use === for comparison
If possible can you give more code to understand the problem
Upvotes: 0