我已经为我的表弟制作了一个表格,将在她的工作中用于她的班级注册。代码的作用是当您从第一个框中选择一个选项时,第二个框会显示日期、日期和时间。我从最近在这里找到的一篇文章中得到了它。我的问题是有人提交后它没有出现在电子邮件中。我怎样才能让它发挥作用,以便它可以发送并显示在电子邮件中。
表单示例http://crl.x10.mx/rosie_class_form.html
这是我在电子邮件中收到的...
消息发送时间:2012 年 12 月 22 日,星期六
姓名:约翰·多伊
电子邮件:yours@email.com
电话:222-222-2222
课程和时间:<-- 部分未出现
评论:
我会在那里见你
除了课程和时间部分之外,所有内容都已发送。
html 代码:(正文之间的代码)choice_1 = 类和choice_2 = 时间
Name <input type="text" id="full_name" name="full_name" value="full_name" onBlur="if(this.value == ''){ this.value = 'full_name'; this.style.color = '#BBB';}" onFocus="if(this.value == 'full_name'){ this.value = ''; this.style.color = '#000';}" style="color:#BBB;" /><br /><br />
Phone <input type="text" id="phone" name="phone" value="xxx-xxx-xxxx" onBlur="if(this.value == ''){ this.value = 'xxx-xxx-xxxx'; this.style.color = '#BBB';}" onFocus="if(this.value == 'xxx-xxx-xxxx'){ this.value = ''; this.style.color = '#000';}" style="color:#BBB;"/><br /><br />
Email <input type="email" id="email" name="email" value="example@domain.com" onBlur="if(this.value == ''){ this.value = 'example@domain.com'; this.style.color = '#BBB';}" onFocus="if(this.value == 'example@domain.com'){ this.value = ''; this.style.color = '#000';}" style="color:#BBB;" /><br /><br />
Select your class and time.
<br />
<select name="choice_1" id="choice_1" onChange="choice_1(this.'choice_1');">
<option value="0" selected="selected">Class...</option>
<option value="1">Beginners Cake</option>
<option value="2">Basic Cake</option>
<option value="3">Cake</option>
<option value="4">Candy</option>
<option value="5">Cookie</option>
<option value="6">Sugar Cookie</option>
<option value="7">CupCake</option>
<option value="8">Flower</option>
<option value="9">Fondant</option>
<option value="10">Gum paste</option>
</select>
<br />
<select name="choice_2" id="choice_2" onChange="choice_2(this.'choice_2');">
<option value="0" selected="selected">Time...</option>
<option value="1">Monday 01/07/13 6:30 to 10:30pm</option>
<option value="2">Wednesday 01/09/13 5:30 to 7:45pm</option>
<option value="2">Wednesday 01/09/13 10:00 to 12:00am</option>
<option value="3">12</option>
<option value="4">11</option>
<option value="5">13</option>
<option value="6">10</option>
<option value="7">9</option>
<option value="8">7</option>
<option value="9">5</option>
<option value="10">4</option>
</select>
<input type="hidden" name="choice_1" id="choice_1" value=""/>
<input type="hidden" name="choice_2" id="choice_2" value=""/>
<br /><br />
Comments (<span class="optional">Optional</span>) <br />
<textarea name="message" id="message" rows="10" cols="40"></textarea>
<br /><br />
<strong>Please add these numbers:</strong>
<span id="digit1"></span> +
<span id="digit2"></span> =
<input type="text" id="answer" size="2">
<br />
<div id="status"><button type="button" id="myBtn" onClick="ajax_postContact();">Send Now</button></div>
class_signups.js(随机 js 名称)
function s () {
var choice_1 = document.getElementsByName("choice_1");
for ( var i = 0; i < choice_1.length; i++ ) {
if ( choice_1[i].checked ){
var val = choice_1[i].value;
return val;
}
}
}
function ajax_postContact(){
var msg = document.getElementById("message").value;
var answer = document.getElementById("answer").value;
var fn = document.getElementById("full_name").value;
var ph = document.getElementById("phone").value;
var em = document.getElementById("email").value;
var digit1 = parseInt(document.getElementById("digit1").innerHTML);
var digit2 = parseInt(document.getElementById("digit2").innerHTML);
///// error checking ////
var sum = digit1 + digit2;
if(answer == null || answer == ""){
alert("Please add the numbers");
return false;
}
else if(answer != sum){
alert("Your answer to the math problem is wrong. Please try again.");
return false;
}
else if(fn == null || fn == ""){
alert("Please type your name");
return false;
}
else if(em == null || em == ""){
alert("Please type your email address");
return false;
}
else if(msg == null || msg == ""){
alert("Please leave a message");
return false;
}
else{
var hr = new XMLHttpRequest();
var url = "signups.php";
var vars = "full_name="+fn+"&phone="+ph+"&email="+em+"&choice_1="+s()+"&message="+msg;
hr.open("POST", url, true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200){
var return_data = hr.responseText;
document.getElementById("status").innerHTML = return_data;
}
}
hr.send(vars);
document.getElementById("status").innerHTML = "<img src='images/loaderblue.gif' alt='Loader'>";
document.getElementById("full_name").value = "";
document.getElementById("phone").value = "";
document.getElementById("email").value = "";
document.getElementById("message").value = "";
document.getElementById("answer").value = "";
}
}
choice1&2.js(与选择部分一起使用)
$(document).ready(function(){
$("#choice_1").change(function() {
if($(this).data('options') == undefined){
/*Taking an array of all options-2 and kind of embedding it on the select1*/
$(this).data('options',$('#choice_2 option').clone());
}
var id = $(this).val();
var options = $(this).data('options').filter('[value=' + id + ']');
$('#choice_2').html(options);
});
});