I have an HTML form whose action should be set dynamically through JavaScript. How do I do it?
Here is what I am trying to achieve:
<script type="text/javascript">
function get_action() { // Inside script tags
return form_action;
}
</script>
<form action=get_action()>
...
</form>
You cannot invoke JavaScript functions in standard HTML attributes other than
onXXX. Just assign it during window onload.You see that I’ve given the form a
name, so that it’s easily accessible indocument.Alternatively, you can also do it during
submitevent: