If i have a form which action should differ according to some session variable . How can i change the action of the form dynamically so that on client click of specific link button i could submit the form with the required action.
<form id="myform" action="I wanna to change it dynamically" method="post" >
<%-------------%>
</form>
<script type="text/javascript">
function submitform()
{
document.myform.submit();
}
</script>
For example :
If session["emp"] = 1 then the action is /A.aspx
If session["emp"] = 2 then the action is /B.aspx
Option 1
I typically place server values in hidden fields when the form loads so that I can interact with them in JavaScript:
Option 2
If you simply want the form action to change and require no other client-side processing, simply change the form action on the server (you’ll need to add
runat="server"to your form tag):Markup:
C# (or your preferred server side language)