please I am using wordpress with contact form 7.
I have to add a dropdown menu to choose a working date to visit. I used javascript to extract the dates. When I tried the code without contact form 7, it worked well, but when I tried to include it the new date object and the new array, it didn't work.
Here is a simple example just to get what I want to do:
<script>
function GetDates(daysToAdd, startDate = new Date()) {
var aryDates = [];
var i = 0;
var dts = 0
while (dts < daysToAdd) {
var currentDate = new Date();
currentDate.setDate(startDate.getDate() + i);
if (currentDate.getDay() < 5 || currentDate.getDay() > 5) {
aryDates.push(DayAsString(currentDate.getDay()) + ", " + currentDate.getDate() + " " + MonthAsString(currentDate.getMonth()) + " " + currentDate.getFullYear());
dts ++;
}
i ++;
}
return aryDates;
}
function MonthAsString(monthIndex) {
var d = new Date();
var month = new Array();
month[0] = "يناير";
month[1] = "فبراير";
month[2] = "مارس";
month[3] = "أبريل";
month[4] = "مايو";
month[5] = "يونيو";
month[6] = "يوليو";
month[7] = "أوت";
month[8] = "سبتمبر";
month[9] = "أكتوبر";
month[10] = "نوفمبر";
month[11] = "ديسمبر";
return month[monthIndex];
}
function DayAsString(dayIndex) {
var weekdays = new Array(7);
weekdays[0] = "الأحد";
weekdays[1] = "الإثنين";
weekdays[2] = "الثلثاء";
weekdays[3] = "الأربعاء";
weekdays[4] = "الخميس";
weekdays[5] = "الجمعة";
weekdays[6] = "السبت";
return weekdays[dayIndex];
}
</script>
<h3>المعلومات الشخصية:</h3>
<label> الإسم الكامل (مطلوب):
[text* f-name] </label>
<label> بريدك الإلكتروني (مطلوب):
[email* c-email] </label>
<label> رقم الهاتف (مطلوب):
[tel phone] </label>
<h3>خيارات الموعد:</h3>
<label> تاريخ الموعد (مطلوب)
[select date id:dates1]</label>
<script>
var aryDates = GetDates(7);
let dates_list = "";
var combodts = document.getElementById("dates1");
combodts.options.length = 0;
var opt
combodts.add(opt, 0);
for (var i = 0; i < aryDates.length; i++) {
dates_list = dates_list.concat("'", aryDates[i], '\' ');
opt = document.createElement("option");
opt.text = aryDates[i];
opt.value = i;
combodts.add(opt, 0);
}
</script>
<label> الوقت المناسب للموعد (مطلوب)</label>
[radio tyme "الفترة الصباحية" "الفترة المسائية"]
<h3>وصف الحالة</h3>
<label> وصف للحالة (مطلوب)
[textarea* desc] </label>
[submit "تقديم الطلب"]
i solved it it working now the problem was with the blanc lines when i deleted the blanc lines from the js script and put the new date and new array between () (new date()) (new array()) the contact form 7 accepted the js code and it working without any problem