Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

this.form.submit() not working after clicking div element in form

I was trying to test form submission using mouse clicks but the form doesn't seem to submit with vanilla javascript.

I'm using this simple markup and code:

<form name="form" id="price" action="" method="post">
<div class="category" name="price" value="50 dollars" 
onClick="this.form.submit();"
>price</div>

</form>

<?php
echo $_POST['price'];

?>

I can submit the form with Jquery, but I don't understand why this.form.submit() is not working with vanilla javascript? I'm using Chrome to test this.

like image 256
user701510 Avatar asked Dec 05 '11 07:12

user701510


1 Answers

A div is not a form element. There is no this.form for it.

You can still do document.forms.form.submit() (.form since you have name="form")

like image 69
David Hedlund Avatar answered Sep 21 '22 23:09

David Hedlund