I'm trying to retrieve some elements from my form with getElementById. Everything is ok. I can retrieve all elements except for the checkboxes when they're not checked. What can I do?
Here is my jquery code:
x$("input#surveymodsubmit").click(function() {
var resp = confirm("<?php echo Yii::t('general', 'Do you want the notification emails will be sent?'); ?>");
if(resp == true) {
$(document.getElementById("token-form")).append('<input type="hidden" id="SendMails" name="SendMails" value="YES" />');
}
else {
$(document.getElementById("token-form")).append('<input type="hidden" id="SendMails" name="SendMails" value="NO" />');
}
var data = serialize(document.getElementById("token-form"));
if(!checkRequiredBeforeSubmit(data)) return;
x$().xhr('<?php echo $this->createUrl('token/updateMotives', array('id'=>$model->id)); ?>', {
method: 'POST',
async: true,
data: urlstringserialize(data),
callback: function() {$("div.submitmotives").html(data); $("div.submitmotives").show(1000); $("div.submitmotives").delay(4000).hide(1000);}
});
And here is a sample of my form:
<form id="token-form" action="/index.php?r=token/view&id=2483982" method="post"><div class="section row" id="divQ1">
<div class="section row principal_question">
<label class="question_nps">¿Recomendaria usted el Algarve Natur a sus colegas, familiares o amigos? </label> </div>
<div class="section row questionhelpmaxmin">
<label class="col one-third question_help_min">No recomendaria</label> <div class="col one-third"> </div>
<label class="col one-third question_help_max">Recomendaria activamente</label> </div>
<div class="section row">
<div class="col one emptynum"></div>
<div class="col one"><label class="radionum ">0</label><input value="0" class="radionpsnum" name="Q1" id="Q1" type="radio"></div><div class="col one"><label class="radionum ">1</label><input value="1" class="radionpsnum" name="Q1" id="Q1" type="radio"></div><div class="col one"><label class="radionum ">2</label><input value="2" class="radionpsnum" name="Q1" id="Q1" type="radio"></div><div class="col one"><label class="radionum ">3</label><input value="3" class="radionpsnum" name="Q1" id="Q1" type="radio"></div><div class="col one"><label class="radionum ">4</label><input value="4" class="radionpsnum" name="Q1" id="Q1" type="radio"></div><div class="col one"><label class="radionum ">5</label><input value="5" class="radionpsnum" name="Q1" id="Q1" type="radio"></div><div class="col one"><label class="radionum ">6</label><input value="6" class="radionpsnum" name="Q1" id="Q1" type="radio"></div><div class="col one"><label class="radionum ">7</label><input value="7" class="radionpsnum" name="Q1" id="Q1" type="radio"></div><div class="col one"><label class="radionum ">8</label><input value="8" class="radionpsnum" checked="checked" name="Q1" id="Q1" type="radio"></div><div class="col one"><label class="radionum ">9</label><input value="9" class="radionpsnum" name="Q1" id="Q1" type="radio"></div><div class="col one"><label class="radionum radionumlast">10</label><input value="10" class="radionpsnum" name="Q1" id="Q1" type="radio"></div> <div class="col one emptynum"></div>
</div>
<div class="section row principal_question">
<label>Por favor indique qué es lo que mas valora de nuestros servicios</label></div>
<div class="section row"><label class="checkbox"><input checked="checked" value="1" name="Q3_QO6" id="Q3_QO6" type="checkbox">Las mejores instalaciones que he visto nunca.</label></div><div class="section row"><label class="checkbox"><input value="1" name="Q3_QO7" id="Q3_QO7" type="checkbox">Instalaciones en buen estado</label></div><div class="section row"><label class="checkbox"><input value="1" name="Q3_QO8" id="Q3_QO8" type="checkbox">Personal amable y servicial</label></div><div class="section row"><label class="checkbox"><input value="1" name="Q3_QO9" id="Q3_QO9" type="checkbox">Otros motivos. Por favor especifique en Comentarios.</label></div>
</div>
<div class="section row" id="divQ4" style="display: none;">
<div class="section row">
<label style="display: block;">Si desea hacer cualquier comentario por favor hágalo aquí.</label> </div>
<div id="stextarea"><textarea name="Q4" id="Q4"></textarea></div>
Finally, this is what I get from console.log:
Object {Q1: "8", Q4: "", Q394: "8", "": "1", yt0: "Modificar"…}"": "1"Q1: "8"Q4: ""Q394: "8"SendMails: "NO"yt0: "Modificar"
As you could see there's no Q3 element, and that's what I need no matter if the checkbox is checked or not.
This is what I've got checking the checkbox:
Object {Q1: "8", Q3_QO6: "1", Q4: "", Q394: "8", "": "1"…}"": "1"Q1: "8"Q3_QO6: "1"Q4: ""Q394: "8"SendMails: "YES"yt0: "Modificar"
I want something like this:
Object {Q1: "8", Q3_QO6: "", Q4: "", Q394: "8", "": "1"…}"": "1"Q1: "8"Q3_QO6: "1"Q4: ""Q394: "8"SendMails: "YES"yt0: "Modificar"
Aucun commentaire:
Enregistrer un commentaire