How to switch the action field in an HTML form dynamically

<SCRIPT language="JavaScript">
function OnSubmitForm()
{
if(document.pressed == 'Insert')
{
document.myform.action ="insert.html";
}
else
if(document.pressed == 'Update')
{
document.myform.action ="update.html";
}
return true;
}
</SCRIPT>

<FORM name="myform" onSubmit="return OnSubmitForm();">

<INPUT TYPE="SUBMIT" name="Operation" onClick="document.pressed=this.value" VALUE="Insert">

<INPUT TYPE="SUBMIT" name="Operation" onClick="document.pressed=this.value" VALUE="Update">

</FORM>

source

Leave a Reply