Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem with hiding div inside table

ashsa's Avatar
Member
 
Join Date: Feb 2007
Location: New Delhi, India
Posts: 43
#1: Feb 28 '07
I use the following fragment in my html page and I tried using the document.getElementById().style.display='none' to hide the div or the row but neither works..

<table>
<form>
<tr id='myrow'>
<td><div id="divi" title='mydiv'></div></td>
</tr>
</form>
</table>

<input type="submit" name='go' value="Go" onclick='reset();return false;'>

function reset(){
document.getElementById('txt1').value="";
document.getElementById('txt2').value="";
document.getElementById('myrow').style.display='no ne';
alert('hidden!!');
}

The functions empties the textboxes but doesnt hide the row or div and also no alert is given !! Could anyone help ??

Member
 
Join Date: Feb 2007
Posts: 36
#2: Feb 28 '07

re: Problem with hiding div inside table


I got it to work like this in IE7:
Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3.  
  4. <head>
  5. <title>Test</title>
  6. </head>
  7.  
  8. <body>
  9. <table>
  10. <form>
  11. <tr id='myrow'>
  12. <td><div id="divi" title='mydiv'>Text Here</div></td>
  13. </tr>
  14. </form>
  15. </table>
  16. <input type="text" name="txt1">
  17. <input type="text" name="txt2">
  18. <input type="submit" name='go' value="Go" onclick='reset();return false;'>
  19. </body>
  20.  
  21. <script language="javascript">
  22. function reset(){
  23. document.getElementById('txt1').value="";
  24. document.getElementById('txt2').value="";
  25. document.getElementById('myrow').style.display='none';
  26. alert('hidden!!');
  27. }
  28. </script>
  29.  
  30. </html>
  31.  
  32.  
Were you forgetting the <script> tag on the java. Try it and see what you get.

Hope it helps
ashsa's Avatar
Member
 
Join Date: Feb 2007
Location: New Delhi, India
Posts: 43
#3: Mar 1 '07

re: Problem with hiding div inside table


Thank you Movie King !!
The same thing worked on my System at last :-)
After breaking my head with the prob for about six hours I found that there seems to be an inbuilt function named reset() which i was using for my function ..

Just changed the name of the function and it started working ...

Quote:

Originally Posted by movieking81

I got it to work like this in IE7:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3.  
  4. <head>
  5. <title>Test</title>
  6. </head>
  7.  
  8. <body>
  9. <table>
  10. <form>
  11. <tr id='myrow'>
  12. <td><div id="divi" title='mydiv'>Text Here</div></td>
  13. </tr>
  14. </form>
  15. </table>
  16. <input type="text" name="txt1">
  17. <input type="text" name="txt2">
  18. <input type="submit" name='go' value="Go" onclick='reset();return false;'>
  19. </body>
  20.  
  21. <script language="javascript">
  22. function reset(){
  23. document.getElementById('txt1').value="";
  24. document.getElementById('txt2').value="";
  25. document.getElementById('myrow').style.display='none';
  26. alert('hidden!!');
  27. }
  28. </script>
  29.  
  30. </html>
  31.  
  32.  
Were you forgetting the <script> tag on the java. Try it and see what you get.

Hope it helps

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4: Mar 2 '07

re: Problem with hiding div inside table


Quote:

Originally Posted by ashsa

Thank you Movie King !!
The same thing worked on my System at last :-)
After breaking my head with the prob for about six hours I found that there seems to be an inbuilt function named reset() which i was using for my function ..

Just changed the name of the function and it started working ...

Yes, never use reserved words used in forms and other places, e.g. name, submit, reset, action...

They cause problems in IE, and anyway it's bad practice.
Newbie
 
Join Date: Jan 2009
Posts: 1
#5: Jan 6 '09

re: Problem with hiding div inside table


If you are having trouble tracking down errors, make sure any functions that are case-sensitive, such as getElementById(), are typed correctly.
Reply