0

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?

0

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

By the way this type of toggling can cause trouble with inline elements, check this link : dustindiaz.com/seven-togglers
0

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

Comments

0

Missing elements

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.

Use Firbug

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.