I have a simple function to toggle visibility of whatever. I use it in many places and I know it works fine.

<script type="text/javascript">
<!--
function toggle_visibility(id) {
  var e = document.getElementById(id);
  if (e.style.display == 'block')
    e.style.display = 'none';
  else
    e.style.display = 'block';
}
//-->
</script>

I'm now using this in a program and it's not working at all.

$id = "add_more_q";
?>
<div><font color='blue'><a onlick='toggle_visibility("<?php echo $id; ?>")'>Add More Questions</a></font></div>
<div id='<?php echo $id;?>' style='display: none'>
<?php
$form->form_ddbox("Add Question Two",'',$add_question_array,$errors,1,0,0);
//so on...
echo "</div>";

form_ddbox creates a drop down box taking an array and the name and other stuff.

The only difference between this program any any previous pages where I used the java function is that this one is inside of <form> tags. Does java not work inside <form>? I am so confused by this. I literally copy and pasted code and it all of a sudden doesn't work.

Well, look at this line:

<div><font color='blue'><a [B]onlick[/B]='toggle_visibility("<?php echo $id; ?>")'>Add More Questions</a></font></div>

I think it should be onclick, not onlick

revised code for proper case sensitivity syntax. "onClick" is the proper case sensitivity syntax because Java script is a case sensitive programming language

Wow. I copy and pasted from working code. Maybe my version is different from the one on the server. Thanks guys.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.