html - Php Post Action -
i want post action according select entries. however, code not work. how can do? thank you.
<form action=<?php echo $filename; ?> method="post"> <br/> <input type="submit" name="select" value="a" onclick="selecta()" /> <br/> <input type="submit" name="select" value="b" onclick="selectb()" /> <br/> <input type="submit" name="select" value="c" onclick="selectc()" /> </form> <?php function selecta(){ $filename = "a.php"; } function selectb(){ $filename = "b.php"; } function selectc(){ $filename = "c.php"; } ?>
you cannot use php dynamically change html. use javascript:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> <form action="#" method="post" id="myform"> <br/><input type="submit" name="select" value="a" onclick="selecta()"/> <br/><input type="submit" name="select" value="b" onclick="selectb()"/> <br/><input type="submit" name="select" value="c" onclick="selectc()"/> </form> <script> var action = 'a.php'; $(function(){ $('#myform').submit(function(){ $(this).attr('action', action); }); }); function selecta() { action = 'a.php'; } function selectb() { action = 'b.php'; } function selectc() { action = 'c.php'; } </script>
Comments
Post a Comment