Jump to content

[SOLVED] show/hide


rasherb

Recommended Posts

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?

 

Link to comment
https://forums.phpfreaks.com/topic/82235-solved-showhide/
Share on other sites

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>";

 

?>

 

Link to comment
https://forums.phpfreaks.com/topic/82235-solved-showhide/#findComment-418424
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.