one textbox one button two different pages in html -


i trying assign textbox value php variable problem want 1 button work 2 different pages i.e if enter in text box 'a'and click on button should redirect 'a.php' page if write in text box 'b' should redirect 'b.php'.

so 1 textbox,one button 2 different pages.

code :

<html><head> <meta charset="utf-8" /> <script> function submitform(action) {     document.getelementbyid('a').action = action;     document.getelementbyid('a').submit(); } function submitform1(action) {     document.getelementbyid('b').action = action;     document.getelementbyid('b').submit(); }  </script> </head>  <body >    <h3><font face="verdana" size="3"><b>enter text:</b></h3>   <input type="text"  align="right" style="font-size:15pt;height:32px;"><br><br>      <form action="b.php" name="b" id="b" method="post">  <form action="a.php" name="a" id="a" method="post">   <input type="submit" onclick="submitform('a.php')" value="try"  name="a">  <input type="button" onclick="submitform1('b.php')" value="try" name="b">        </form>     </form>   </body> </html> 

you can change action onsubmit based on text inside input.

<html> <head>     <script type="text/javascript">         function onsubmit_handler(){             var myform = document.getelementbyid('myform');             var data = document.getelementbyid('data').value;             if(data == "a")                 myform.setattribute('action', 'a.php');             else if(data == "b")                 myform.setattribute('action', 'b.php');             else                 myform.setattribute('action', 'error.php');         }     </script> </head> <body>     <h3>enter text:</h3>     <form id="myform" method="post" onsubmit="onsubmit_handler()">         <input type="text" id="data" name="data" value="">         <input type="submit" value="post">     </form> </body> </html> 

test code here : http://jsfiddle.net/eg9s4/


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -