selecting the value and then submitting the form using vue.js dosent work

Multi tool use
Multi tool use


selecting the value and then submitting the form using vue.js dosent work



My problem is that when I select the input value and then submit the form my answer value from the form is empty in answer.php - $_POST['answer']
here is my html code:


answer


answer.php


$_POST['answer']


<form action="answer.php" ref="send" method="post" class="container">
<h1><?= $question['Question']; ?></h1>
<input type="hidden" name="id" value="<?= $question['ID']; ?>">













</form>



and here is my vue code:


new Vue({
el: '#app',
data: {
answer: 0,
},
methods: {
demo() {
this.answer = 1;
},
},
watch: {
answer(val) {
this.$refs.send.submit();
},
},
});



The form is send like I have never select anything of the form, no answer. What I am doing wrong?


answer



UPDATE: I am taking about when someone clicks inside the div, but NOT at the text itself. In the 'white' space in the div. That's when my problem happen and I want them to be able to click on the div and select the answer, instead only on the text.


div



In the gif below you can see 1 is the value of answer and demo123 is the value of the id and when i click on the radio button you can see them changed before the form is send, but you can also see that when the answer.php is loaded the value of id is value (the default one) and there is no answer value to be found.
enter image description here


1


answer


demo123


id


answer.php


id


value


answer





i try test your code , it work fine. In my answer.php file, It display $_POST['answer'] . You should check your request in network chrome
– Hưng hoàng
Jul 3 at 2:34





I am getting only the hidden id input from the post question i can see in the network tab. I don't see any answer value in there, the problem comes from when it is clicked on the div instead on the text itself. have you tried that, because this is the functionality I want to be able to use
– Dimitar
Jul 3 at 5:30


id


answer


div




1 Answer
1



I manage to get it work using this code


methods: {
demo() {
this.$refs.send[1].checked = true;
this.$refs.send.submit();
},
},



So, when now someone clicked in the div the first radio button it's selected and then the form it is send. If someone have a better solution, please let me know! thanks!


div






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Pu6UfaWeg,22iB
v,BFCb fm0G5khVEAsDZ6l5Ryw oJG7ilc

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications