Javascript 如何获取要通过电子邮件发送的选定部件
我已经为我表妹准备了一份表格,准备用它来报名参加她的工作。代码的作用是,当您从第一个框中选择一个选项时,第二个框将显示日期、日期和时间。我在最近的一篇文章中找到了它。我的问题是,在有人提交后,它不会出现在电子邮件中。我如何才能让它正常工作,以便它可以被发送并显示在电子邮件中 范例 这是我在电子邮件中得到的 发送日期:2012年12月22日,星期六 姓名:无名氏 电邮:yours@email.com 电话:222-222-2222Javascript 如何获取要通过电子邮件发送的选定部件,javascript,jquery,html,forms,Javascript,Jquery,Html,Forms,我已经为我表妹准备了一份表格,准备用它来报名参加她的工作。代码的作用是,当您从第一个框中选择一个选项时,第二个框将显示日期、日期和时间。我在最近的一篇文章中找到了它。我的问题是,在有人提交后,它不会出现在电子邮件中。我如何才能让它正常工作,以便它可以被发送并显示在电子邮件中 范例 这是我在电子邮件中得到的 发送日期:2012年12月22日,星期六 姓名:无名氏 电邮:yours@email.com 电话:222-222-2222 类与时间:在哪里定义函数choice1()和choice2()?您
类与时间:在哪里定义函数
choice1()
和choice2()
?您的s()
函数使用了choice\u 1[i]。选中了,这只适用于复选框,而不适用于选择菜单。@对于选项\u 1[i]。选中了,我已将其更改为choice\u 1[i]。选中了。在您的
中定义函数choice1()和choice2()是什么意思。这将尝试调用函数choice\u 1()
,但您从未定义过此函数。您有一个名为choice\u 1
和choice\u 2
的
。为什么两者都需要?所选的属性对输入不起作用。在“select name=“select1”id=“select1”>”和“select name=“select2”id=“select2”>”找到一篇文章并在onChange和隐藏部分中尝试了它之前,我就使用过这种方法。
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>
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 = "";
}
}
$(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);
});
});