Jquery 从电子邮件的下拉框中选择值(未显示)

问题描述 投票:0回答:0

我有一个在 php 中用 for 循环生成的下拉表单,我试图获取选定的值,这是一个要通过电子邮件发送的日期

在索引页面上,我基本上如下所示。这不是完整的代码,因为我的循环更复杂,但我不认为问题在那里。

在我的 custom.js 文件中,我有如下内容。问题必须是在以下代码中选择的预订日期。我对 jquery 不太好,它一定很傻。

我得到的所有输入都是正确的。我的问题是选择下拉框。

我做错了什么?

我的最后一个文件是发送电子邮件的 send.php。除了预订日期外,没有任何问题,所有字段都已正确发送。

作为输入单选框,我在日期工作之前有代码。但是在用 php 动态创建的选择下拉框中它没有。

$('#send').live("click", function() {
  var url = 'send.php';
  var error = 0;
  var $contactpage = $(this).closest('.ui-page');
  var $contactform = $(this).closest('.contact-form');
  $('.required', $contactform).each(function(i) {
    if ($(this).val() === '') {
      error++;
    }
  });
  // each
  if (error > 0) {
    alert('Please fill in all the mandatory fields. Mandatory fields are marked with an asterisk *.');
  } else {
    var firstname = $contactform.find('input[name="add_name"]').val();
    var lastname = $contactform.find('input[name="add_surname"]').val();
    var amount = $contactform.find('input[name="add_seats"]:checked').val();
    var reservationDate = $contactform.find('select[name="add_r_date"]:selected').val();
    var mobilephone = $contactform.find('input[name="add_phone"]').val();
    var email = $contactform.find('input[name="email"]').val();
    var message = $contactform.find('input[name="add_note"]').val();

    //submit the form.send.php takes from below.
    $.ajax({
      type: "GET",
      url: url,
      data: {
        firstname: firstname,
        lastname: lastname,
        //  state : state,
        amount: amount,
        reservationDate: reservationDate,
        mobilephone: mobilephone,
        email: email,
        message: message
      },
      success: function(data) {
        if (data == 'success') {
          console.log(data);
          // show thank you
          window.location = 'thankyou.php'
          //$contactpage.find('.contact-thankyou').show();
          //$contactpage.find('.contact-form').hide();
        } else {
          alert('Unable to send your message. Please try again.');
        }
      }
    });
    //$.ajax

  }
  return false;
});
<div id = "contact-form" class="col-12">
<form action="" id="add-form" class="contact-form">     


 //$day=date('l,d M',strtotime("+$i day"));

for($i=0;$i<=60;$i++){
<option value=$InsDay>$day</option>
}
</select>

php html jquery select dropdown
© www.soinside.com 2019 - 2024. All rights reserved.