rasherb Posted December 18, 2007 Share Posted December 18, 2007 Can someone help me make parts of a page show/hide when the user clicks a button? I'm writing in PHP now, but I hear javascript will do this better, particularly because I am trying to show/hide parts of a form while retaining user input. Say this is my page: <?php echo "<div>"; echo "<form name=\"form\" method=\"post\" action=\"submit.php?useridnum=$usernum\">"; echo "Title: <input type=\"text\" name=\"title\" size=\"70\"></textarea>"; echo "<a href=\"\"><img border=\"0\" src=\"openclose.gif\"></a>"; echo "Category: <input type=\"text\" name=\"category\" size=\"70\"></textarea>"; echo "Stakeholders: <input type=\"text\" name=\"stake\" size=\"70\"></textarea>"; echo "Objective: <input type=\"text\" name=\"objective\" size=\"70\"></textarea>" echo "</div>"; echo "<div>"; echo "Title2: <input type=\"text\" name=\"title2\" size=\"70\"></textarea>"; echo "<a href=\"\"><img border=\"0\" src=\"openclose.gif\"></a>"; echo "Category2: <input type=\"text\" name=\"category2\" size=\"70\"></textarea>"; echo "Stakeholders2: <input type=\"text\" name=\"stake2\" size=\"70\"></textarea>"; echo "Objective2: <input type=\"text\" name=\"objective2\" size=\"70\"></textarea>" echo "</div>"; echo "<div>"; echo "<input type=\"submit\" value=\"Submit\" />"; echo "</div>"; ?> I want to hide/show using javascript enabled buttons (onclick?) instead of the links. Never programmed javascript before. Can anyone help? Quote Link to comment Share on other sites More sharing options...
rasherb Posted December 18, 2007 Author Share Posted December 18, 2007 Nevermind. Solved using the Internets! Quote Link to comment Share on other sites More sharing options...
rasherb Posted December 19, 2007 Author Share Posted December 19, 2007 Only hang up is I need to name all of my divs individually and uniquely. Can anyone help me with a function where I can show/hide individual divs, but keep the same id on all divs? The thing looks like this for a javascript show/hide: <?php <head> <script language=javascript type='text/javascript'> function showhide(id){ if (document.getElementById){ obj = document.getElementById(id); if (obj.style.display == \"none\"){ obj.style.display = \"\"; } else { obj.style.display = \"none\"; } } } </script> </head> echo "<a href=\"#\" onclick=\"showhide('titlebox'); return(false);\"><img border=\"0\" src=\"open.gif\">"; echo "<div id=\"titlebox\" style=\"display: none;\">"; echo "<form name=\"form\" method=\"post\" action=\"submit.php?useridnum=$usernum\">"; echo "Title: <input type=\"text\" name=\"title\" size=\"70\"></textarea>"; echo "<a href=\"\"><img border=\"0\" src=\"openclose.gif\">[/url]"; echo "Category: <input type=\"text\" name=\"category\" size=\"70\"></textarea>"; echo "Stakeholders: <input type=\"text\" name=\"stake\" size=\"70\"></textarea>"; echo "Objective: <input type=\"text\" name=\"objective\" size=\"70\"></textarea>" echo "</div>"; echo "<a href=\"#\" onclick=\"showhide('subtitlebox'); return(false);\"><img border=\"0\" src=\"open.gif\">"; echo "<div id=\"subtitlebox\" style=\"display: none;\">"; echo "Title2: <input type=\"text\" name=\"title2\" size=\"70\"></textarea>"; echo "<a href=\"\"><img border=\"0\" src=\"openclose.gif\">[/url]"; echo "Category2: <input type=\"text\" name=\"category2\" size=\"70\"></textarea>"; echo "Stakeholders2: <input type=\"text\" name=\"stake2\" size=\"70\"></textarea>"; echo "Objective2: <input type=\"text\" name=\"objective2\" size=\"70\"></textarea>" echo "</div>"; echo "<div>"; echo "<input type=\"submit\" value=\"Submit\" />"; echo "</div>"; ?> Quote Link to comment Share on other sites More sharing options...
emehrkay Posted December 19, 2007 Share Posted December 19, 2007 No. Ids are meant to be unique identifiers. I dont see anything wrong with your code, well you never close the link around the open.gif. Why do you want to have the ids on the divs be the same anyway? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.