盒子有两个表单选项

时间:2016-09-05 21:16:29

标签: javascript jquery html

我有一个表单,显示一个有两个选项的框,一个是"接受"而另一个"不接受"。事实证明,当用户使用发送电子邮件时,他可以使用标记为"不接受"的按钮发送电子邮件。有什么方法可以让它验证吗?

HTML

                <div class="form">
                    <h4>Valor do consórcio: <span class="slider-value quote-form-element" data-name="Valor | Automóvel" data-slider-id="consorcio-auto">R$ <span></span></span></h4>
                    <div class="slider" data-slider-min="20000" data-slider-max="100000" data-slider-start="23192" data-slider-step="1000" data-slider-id="consorcio-auto"></div>

                    <h4>Seus dados:</h4>
                    <input type="text" name="Nome" placeholder="Nome..." class="quote-form-element" />
                    <input type="text" name="Cidade" placeholder="Cidade/UF..." class="quote-form-element quote-form-client-email last" />                           
                    <input type="text" name="Número de Telefone" placeholder="Telefone..." class="quote-form-element telefone" />
                    <input type="text" name="Endereço de Email" placeholder="E-mail..." class="quote-form-element quote-form-client-email last contact_email" />

                    <h4>Política de Privacidade</h4>
                    <div class="checkbox quote-form-element" data-checked="yes" data-name="Política de Privacidade">

                        <span class="checkbox-status"><i class="fa fa-check"></i></span>
                        <span class="checkbox-values">


                            <span class="checkbox-value-checked" style="font-size: 12px">Li e aceito a politica de privacidade</span>
                            <span class="checkbox-value-unchecked">Não aceito</span> 
                        </span>

                    </div>

                    <button class="button button-navy-blue send-quote" type="button">Simular meu consórcio <i class="fa fa-paper-plane-o"></i></button>



                    <div class="quote-form-thanks">

                        <div class="quote-form-thanks-content">

                                Obrigado pelo seu interesse, retornaremos em breve ;). 
                                <span class="quote-form-thanks-close">Fechar</span>

                        </div>

                    </div>

                </div>

的Javascript

$('.send-quote').click(function () {

    var quoteForm = $(this).parent();
    var quoteFormParent = quoteForm.parent().parent();

    var insuranceType = quoteFormParent.data('quote-form-for');
    var fields = {};
    var fieldID = 0;

    var fieldName = '';
    var fieldValue = '';

    var clientName = '';
    var clientEmail = '';

    var errorFound = false;

    quoteForm.find('.quote-form-element').each(function (fieldID) {

        fieldName = $(this).attr('name');
        if (typeof fieldName == 'undefined' || fieldName === false) {

            fieldName = $(this).data('name');
        }

        if ($(this).hasClass('checkbox')) {

            fieldValue = $(this).data('checked') == 'yes' ? $(this).children('.checkbox-values').children('.checkbox-value-checked').text() : $(this).children('.checkbox-values').children('.checkbox-value-unchecked').text();
        }

        else {

            fieldValue = $(this).is('input') || $(this).is('select') ? $(this).val() : $(this).text();
            if (($(this).is('input') && fieldValue == '') || ($(this).is('select') && fieldValue == '-')) {

                errorFound = true;
                $(this).addClass('error');
            }

            else {

                $(this).removeClass('error');
            }
        }

        if ($(this).hasClass('quote-form-client-name')) clientName = $(this).val();
        if ($(this).hasClass('quote-form-client-email')) clientEmail = $(this).val();

        fields[fieldID] = { 'name': fieldName, 'value': fieldValue };
        fieldID++;

    });

    if (errorFound == false) {

        $.ajax({
            url: '_assets/submit.php',
            data: { 'send': 'quote-form', 'values': fields, 'clientName': clientName, 'clientEmail': clientEmail },
            type: 'post',
            success: function (output) {

                quoteForm.children('.quote-form-thanks').fadeIn(300);
            }

        });
    }

});

page显示&#34;模拟&#34;。

中的内容

1 个答案:

答案 0 :(得分:0)

所以你需要检查是否接受&#34;是Subtasks或不使用无线电输入。

&#13;
&#13;
checked
&#13;
$('.send-quote').click(function() {
  if ($('[name=terms]:checked').val() === 'no') {
    console.log('got an error');
  } else {
    console.log('all good');
  }
});
&#13;
&#13;
&#13;