Link to home
Start Free TrialLog in
Avatar of dohdohdoh
dohdohdoh

asked on

easy way to do If value = x, then form action is "...", else form action is "..."

I need to change my form action based on the country value collected previously, but the way I have it doesn't work. I've also tried

if x then <form name=...action=...method=post> else <form name...
...whole lot of asp form actions....

but that didn't work either, both give expected statement error.

can anyone help me rewrite it so it doesn't complain?

<form name="checkout_PP_LI_Hid" action= <%if (NOT Request.Form("shipping_country")="AU") then "checkout_success.asp" else  "https://www.PayPal.com/cgi-bin/webscr" end if %> method="post">

Open in new window

Avatar of Om Prakash
Om Prakash
Flag of India image

Hi, try this
<%
  Dim formaction
  if Request.Form("shipping_country") ="AU") then 
  	formaction = "https://www.PayPal.com/cgi-bin/webscr" 
  else  
  	formaction = "checkout_success.asp" 
  end if
  %>
  
  <form 
  	name="checkout_PP_LI_Hid" 
  	action= <%=formaction%>
  	method="post">

Open in new window

Hi there

do you want to do this before the form has been posted? If so, it need to be done using javascript. Check the following code. It changes the action value of the form depending on what you select in the dropdown.
If you want to do it depending on the value of a previously posted form, the reply of om_prakash_p should cover you.
<html>
<head>
<title>EE Test file - Question: 25491504 </title>
<script type="text/javascript">
function updFormPost(cnt)
	{
	if (cnt=="AU")
		{ document.getElementById("chkForm").action="https://www.PayPal.com/cgi-bin/webscr"; }
	else
		{ document.getElementById("chkForm").action="checkout_success.asp"; }
	}
</script>
</head>

<body>
<form id="chkForm" name="checkout_PP_LI_Hid" action="checkout_success.asp" method="post">
<select size="1" name="country" onchange="updFormPost(options[selectedIndex].value)">
	<option value=""></option>
	<option value="AU">Australia</option>
	<option value="US">USA</option>
	<option value="UK">United Kingdom</option>
</select>
<input type="submit" />
</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of code-colors
code-colors
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial