Reputation: 801
Can I have the following inside a form tag?
action="handler"
Is this legal? It supposedly runs a javascript function of some sort.
Upvotes: 0
Views: 74
Reputation: 227310
The action
attribute is the URL the browser will submit the form to.
<form action="submitForm.php"><input /></form>
If you want to run JavaScript, you can make handler
something like this:
<form action="javascript:myFunc(this)"><input /></form>
I highly suggest you don't do this, and instead use JavaScript event handlers to capture the onsubmit
event.
<form id="myForm"><input /></form>
<script>
document.getElementById('myForm').addEventListener('submit', function(event){
event.preventDefault(); // prevent the form the submitting.
// the form will only submit if
// it has an "action" attribute
myFunc(this);
});
</script>
Upvotes: 2
Reputation: 11598
Yes it is legal but wont invoke javascript. It will submit the form to the server url specified by 'handler.'
Upvotes: 2