Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to submit form to different url based on input?

Status
Not open for further replies.

alan123

MIS
Oct 17, 2002
149
US
Hi,

I have a simple form:
Code:
<form name=&quot;info&quot; method=&quot;post&quot; action=&quot;page1.php&quot;>
<select name=&quot;sel&quot;>
<option>Yes</option>
<option>No</option>
<input type=&quot;submit&quot; name=&quot;submit&quot;>

I want to submit the form to &quot;page1.php&quot; if user select &quot;Yes&quot;, or submit the form to &quot;page2.php&quot; if user select &quot;No&quot;, how can I write the javascript to verify the value and submit to its respective page? thanks very much.
 
I'm pretty sure that this does it.
Code:
document.info.action = 'somePage.php';
document.info.submit();



-kaht

banghead.gif
 
be sure to change the &quot;name&quot; of your submit button to something other than &quot;submit&quot; or the submit() method will not work.


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
ahh, didn't see you were using a submit button, in that case do it thise way:
Code:
<script language=Javascript>
function submitFunction() {
   if(whatever) {
      document.info.action = 'somePage.php';
   }
   else {
      document.info.action = 'someOtherPage.php';
   }
   return true;
}
</script>
<form name=&quot;info&quot; method=&quot;post&quot; action=&quot;page1.php&quot; onsubmit=&quot;return(submitFunction())&quot;>
<select name=&quot;sel&quot;>
<option>Yes</option>
<option>No</option>
<input type=&quot;submit&quot; name=&quot;submit&quot;>

-kaht

banghead.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top