Cant hide first div

I have a javascript function which hides  a <div> containing forms, tables, text, etc by passing in the id of the div.(For test purposes only)
The function works for all the div(s) except the very first.
Any suggestions why this would be the case ?
//jsp side
<tr><td><button  onclick="toggle();"><u>H</u>ide</button>                
<c:forEach items="${jobList.jobList}" var="job" varStatus="status">
 <div id="divId_${job.jobId}">
 <c:set var="formId" value="formId_${job.jobId}" />
 form:form name="jobForm" id ="${formId}" method="POST" action="jobmenu.htm"     commandName="job">

  function toggle()
   var ID;
   ID= prompt("Enter id \n\r");
    var a = document.getElementById('divId_'+ID);
    if ("inline")
    else if ("none")
    return false;
Who is Participating?
Michel PlungjanConnect With a Mentor IT ExpertCommented:
Why do you show and hide immediately after each other???

Can you show the html produced? Perhaps the ID is not set for the first div

Here is a cleaner script

function toggle() {
  var ID = prompt("Enter id \n\r","");
  if (ID!="") {
    var a = document.getElementById('divId_'+ID);
    if (a) { // could be the user did not enter a correct ID
      var disp =;
      if (disp=="inline") disp="none";
      else if (disp=="none")  disp="inline";
      else disp="none";
  return false;

Open in new window

Sathish David Kumar NConnect With a Mentor ArchitectCommented:
give alert message as id


and right cilck of ur application view sources check whether both div id are same ?
WaponiAuthor Commented:
Michel PlungjanIT ExpertCommented:

Please note a typo I had
else disp=="none";
should be
else disp="none";
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.