iGuest 3 Report post Posted February 20, 2005 Hi there! Is there a way to use JS to change a form's submit target based on which submit button was pressed? Eg. <form action = ""><button type = "submit" onclick = "change form action to register.php">Register</button><button type = "submit" onclick = "change from action to login.php">Login</button></form> Thank you!! Added code tags--CodeFX Share this post Link to post Share on other sites
iGuest 3 Report post Posted February 20, 2005 I took this from an example on the Javascript DOM reference for forms at w3schools.com . I modified it to fit your needs. <html><head><script type="text/javascript">function changeActionAndGo(url){var x=document.forms.myForm;x.action=url;x.submit();}</script></head><body><form name="myForm" action="page.php"><br /><br /><input type="button" onclick="changeActionAndGo('page1.php')" value="Submit to page1.php"><input type="button" onclick="changeActionAndGo('page2.php')" value="Submit to page2.php"></form></body></html> It's a very basic example, and you'll need to modify it to fit your site, but if you have a little experience with JS, that shouldn't be hard. I just demonstrated the concepts. btw, you should put your code in tags. It makes it easier to read. And you might want to check up on your form syntax before actually writing one. There is no <button> tag, and you can't put anything inside an <input> tag. :wink: Share this post Link to post Share on other sites
iGuest 3 Report post Posted February 26, 2005 It's probably easier to have the option block or whatever send an 'action' request that gets parsed by your script through a switch statement and then uses an HTTP header to redirect and uses session variables to temporarily store the relevant data on your client's computer. Share this post Link to post Share on other sites