Cant hide first div

Hello,
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 ?
Thanks.
//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">
     :
     :
</div>

//javascript
  function toggle()
    {
   var ID;
   ID= prompt("Enter id \n\r");
    var a = document.getElementById('divId_'+ID);
    if (a.style.display=="inline")
    {
    a.style.display="none";
    }
    else if (a.style.display=="none")
    {
    a.style.display="inline";
    }
    else
    {
    a.style.display="block";
    a.style.display="none";
    }
    return false;
    }
WaponiAsked:
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 = a.style.display;
      if (disp=="inline") disp="none";
      else if (disp=="none")  disp="inline";
      else disp="none";
    }
  }
  return false;
}

Open in new window

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

alert(ID)

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

Please note a typo I had
else disp=="none";
should be
else disp="none";
0
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.