Aharkus,
I'm sure your method could be made to work but there's a way to do this without using ids. Hence less to worry about in php.
This demo uses jQuery though the same can be achieved (less concisely) in raw javascript:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$(".showHideForm").click(function() {
$(this).closest("div").find("form").toggle();
});
});
</script>
</head>
<body>
<div>
<input class="showHideForm" type="button" value="VAT" />
<form name="demoA" action="" method="get">
<input name="demoA_1" type="text">
<input name="demoA_2" type="text">
</form>
</div>
<div>
<input class="showHideForm" type="button" value="VAT" />
<form name="demoB" action="" method="get">
<input name="demoB_1" type="text">
<input name="demoB_2" type="text">
</form>
</div>
</body>
</html> The trick here is to wrap each button/form set in a div (or some other wrapper, eg. a table row). When a button is clicked, the handler worksrelative to it to discover the corresponding form. This avoids the need for ids, and is both simple and efficient.
Airshow
Airshow
WiFi Lounge Lizard
Moderator
2,683 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372