我目前有下拉选择和使用JavaScript显示/隐藏值的工作代码,这取决于所选择的内容,正如你可以看到下面的代码。我想做的是,根据新建和使用的选择,有三种不同的表单输入。如果选择使用,它会直接进入带有输入的表单。如果你选择新的,它会带来另一个下拉列表,你可以选择租赁或购买,并根据这一点选择另外两个表单显示。我知道如何提交一个表单只是一个表单到PHP使用POST。但是,我的问题是,因为根据下拉,表单会随着不同的输入而变化。我如何使用PHP提交此。我的代码是下面有三个文件newform.php, newForm.js和newformprocess.php.再次发送表单,如果它不改变我知道该怎么做。我遇到的问题是,窗体根据所选的下拉列表而变化。非常感谢你的帮助。谢谢大家。newformprocess.php文件,我知道它看起来不正确的$_POST值等。这是我想使用的代码,所以我错过了。
第一个文件newform.php
<?php include('formProcess.php'); ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Offer Submission Form</title>
<link rel="stylesheet" type="text/css" href="css/mystyle.css">
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript" src="js/newForm.js"></script>
</head>
<body>
<div class="form-style-10">
<h2>Please Select Your Offer Type</h2>
<div class="inner-wrap">
<form action="newformprocess.php" method="post">
<label>Dealership Name:<em class="required-star">*</em></label><input id="fin_dealerName" name="input_1" type="text" placeholder="Dealership Name" />
<label>Which Marketing Medium?<em class="required-star">*</em></label><select id="market" type="select" name="marketing">
<option id="market1" value="marketpick1">Facebook</option>
<option id="market2" value="marketpick2">Website Banner</option>
<option id="market3" value="marketpick3">Radio</option>
<option id="market4" value="marketpick4">TV</option>
<option id="market5" value="marketpick5">Email</option>
<option id="market6" value="marketpick6">Direct Mail</option>
<option id="market7" value="marketpick7">All Channels</option>
</select>
<label>Offer Type?</label><select id="newused" type="select" name="offerType">
<option id="option_1" value="option1">New</option>
<option id="option_2" value="option2">Used</option>
</select>
<div id="new" style="display:none;">
<label>Type of Purchase?</label><select id="newPick" type="select" name="typeOfPurchase">
<option id="newPick_1" value="newPick1">Purchased</option>
<option id="newPick_2" value="newPick2">Leased</option>
</select>
</div>
<!--This div section is for when client select puchased as their new opiton....--->
<div id="purchased" style="display:none;">
<label>Start Date:<em class="required-star">*</em></label><input id="fin_startDate" name="input_2" type="text" placeholder="01/01/2012"/>
<label>End Date:<em class="required-star">*</em></label><input id="fin_endDate" name="input_3" type="text" placeholder="05/07/2015"/>
<label>Year:<em class="required-star">*</em></label><input id="fin_vehicleYear" name="input_4" type="text" placeholder="Vehicle Year"/>
<label>Make:<em class="required-star">*</em></label><input id="fin_make" name="input_5" type="text" placeholder="Make"/>
<label>Model:<em class="required-star">*</em></label><input id="fin_model" name="input_6" type="text" placeholder="Model"/>
<label>Trim:<em class="required-star">*</em></label><input id="fin_trim" name="input_7" type="text" placeholder="Trim of Vehicle"/>
<label>Model #:<em class="required-star">*</em></label><input id="fin_input_5" name="input_8" type="text" placeholder="14325"/>
<label>Stock #:<em class="required-star">*</em></label><input id="fin_input_5" name="input_9" type="text" placeholder="1234"/>
<label>MSRP:<em class="required-star">*</em></label><input id="fin_input_5" name="input_10" type="text" placeholder="$15,995"/>
<label>Selling Price:<em class="required-star">*</em></label><input id="fin_input_5" name="input_11" type="text" placeholder="$12,895"/>
<label>Down Payment:<em class="required-star">*</em></label><input id="fin_input_5" name="input_12" type="text" placeholder="$1,000"/>
<label>$XXX/ Monthly Payment:<em class="required-star">*</em></label><input id="fin_input_5" name="input_13" type="text" placeholder="$198"/>
<label>Last 6 of VIN:<em class="required-star">*</em></label><input id="fin_input_5" name="input_14" type="text" placeholder="123456"/>
<label>Rebate:</label><input id="fin_input_5" name="input_15" type="text" placeholder="Rebate on Vehicle"/>
<label>APR:<em class="required-star">*</em></label><input id="fin_input_5" name="input_16" type="text" placeholder="ARP on Vehicle"/>
<label>Term:<em class="required-star">*</em></label><input id="fin_input_5" name="input_17" type="text" placeholder="Residual Payment on Vehicle"/>
<label>Other Notes(Rebate Info, Special Details etc):</label> <textarea id="fin_textArea" name="input_18" placeholder="Notes" rows=2></textarea>
</div>
<!--This div section is for when client select leased as their new opiton....--->
<div id="leased" style="display:none;">
<label>Start Date:<em class="required-star">*</em></label><input id="fin_startDate" name="input_2" type="text" placeholder="01/01/2012"/>
<label>End Date:<em class="required-star">*</em></label><input id="fin_endDate" name="input_3" type="text" placeholder="05/07/2015"/>
<label>Year:<em class="required-star">*</em></label><input id="fin_vehicleYear" name="input_4" type="text" placeholder="Vehicle Year"/>
<label>Make:<em class="required-star">*</em></label><input id="fin_make" name="input_5" type="text" placeholder="Make"/>
<label>Model:<em class="required-star">*</em></label><input id="fin_model" name="input_6" type="text" placeholder="Model"/>
<label>Trim:<em class="required-star">*</em></label><input id="fin_trim" name="input_7" type="text" placeholder="Trim of Vehicle"/>
<label>Model #:<em class="required-star">*</em></label><input id="fin_input_5" name="input_8" type="text" placeholder="14325"/>
<label>Stock #:<em class="required-star">*</em></label><input id="fin_input_5" name="input_9" type="text" placeholder="1234"/>
<label>MSRP:<em class="required-star">*</em></label><input id="fin_input_5" name="input_10" type="text" placeholder="$15,995"/>
<label>Selling Price:<em class="required-star">*</em></label><input id="fin_input_5" name="input_11" type="text" placeholder="$12,895"/>
<label>Down Payment:<em class="required-star">*</em></label><input id="fin_input_5" name="input_12" type="text" placeholder="$1,000"/>
<label>$XXX/ Monthly Payment:<em class="required-star">*</em></label><input id="fin_input_5" name="input_13" type="text" placeholder="$198"/>
<label>Last 6 of VIN:<em class="required-star">*</em></label><input id="fin_input_5" name="input_14" type="text" placeholder="123456"/>
<label>Rebate:</label><input id="fin_input_5" name="input_15" type="text" placeholder="Rebate on Vehicle"/>
<label>Term:<em class="required-star">*</em></label><input id="fin_input_5" name="input_16" type="text" placeholder="ARP on Vehicle"/>
<label>Residual Value:<em class="required-star">*</em></label><input id="fin_input_5" name="input_17" type="text" placeholder="Residual Payment on Vehicle"/>
<label>Miles Per Year:<em class="required-star">*</em></label><input id="fin_input_5" name="input_17" type="text" placeholder="Residual Payment on Vehicle"/>
<label>Other Notes(Rebate Info, Special Details etc):</label> <textarea id="fin_textArea" name="input_18" placeholder="Notes" rows=2></textarea>
</div>
<!-- IF users picks USED it will go to this section of the form...-->
<div id="used" style="display:none;">
<label>Start Date:<em class="required-star">*</em></label><input id="fin_startDate" name="input_2" type="text" placeholder="01/01/2012"/>
<label>End Date:<em class="required-star">*</em></label><input id="fin_endDate" name="input_3" type="text" placeholder="05/07/2015"/>
<label>Year:<em class="required-star">*</em></label><input id="fin_vehicleYear" name="input_4" type="text" placeholder="Vehicle Year"/>
<label>Make:<em class="required-star">*</em></label><input id="fin_make" name="input_5" type="text" placeholder="Make"/>
<label>Model:<em class="required-star">*</em></label><input id="fin_model" name="input_6" type="text" placeholder="Model"/>
<label>Trim:</label><input id="fin_trim" name="input_7" type="text" placeholder="Trim of Vehicle"/>
<label>Stock #:<em class="required-star">*</em></label><input id="fin_input_5" name="input_9" type="text" placeholder="1234"/>
<label>Selling Price:<em class="required-star">*</em></label><input id="fin_input_5" name="input_11" type="text" placeholder="$12,895"/>
<label>Down Payment:<em class="required-star">*</em></label><input id="fin_input_5" name="input_12" type="text" placeholder="$1,000"/>
<label>APR:<em class="required-star">*</em></label><input id="fin_input_5" name="input_16" type="text" placeholder="ARP on Vehicle"/>
<label>Term:<em class="required-star">*</em></label><input id="used_term" name="input_14" type="text" placeholder=""/>
<label>Other Notes(Rebate Info, Special Details etc):</label><textarea id="fin_textArea" name="input_18" placeholder="Notes" rows=2></textarea>
</div>
<div class="button-section"><br />
<input type="submit" name="submit" value="Submit Offer" />
</div>
</form>
</body>
</div>
</div>
</html>
第二个文件newForm.js
$(document).ready(function() {
$select = $('#newused');
$('#newused').on('mousedown',function(){
if($(this).val() == "option1"){
if($('#new').is(":hidden")){
$('#new').show();
}
$('#used').hide();
}
if($(this).val() == "option2"){
if($('#used').is(":hidden")){
$('#used').show();
}
$('#new').hide();
$('#leased').hide();
$('#purchased').hide();
}
});
$select = $('#newPick');
$('#newPick').on('mousedown',function(){
if($(this).val() == "newPick1"){
if($('#purchased').is(":hidden")){
$('#purchased').show();
}
$('#leased').hide();
$('#used').hide();
}
if($(this).val() == "newPick2"){
if($('#leased').is(":hidden")){
$('#leased').show();
}
$('#purchased').hide();
$('#used').hide();
}
});
});
最后一个文件newformprocess.php
<?php
if(isset($_POST["submit"]))
{
// Checking For Blank Fields....
if($_POST['offerType']==""|| $_POST['typeOfPurchase'] =="" ||$_POST['marketing']==""||$_POST['input_1']==""||$_POST['input_2']==""||$_POST['input_3']==""||$_POST['input_4']==""||$_POST['input_5']==""||
$_POST['input_6']==""||$_POST['input_7']==""||$_POST['input_9']==""||$_POST['input_10']==""||$_POST['input_11']==""||$_POST['input_12']==""||$_POST['input_13']==""||$_POST['input_14']=="")
{
?>
<script>
alert("Please complete the text marked with an *.");
</script>
<?php
}
else{
$Offer = $_POST['offerType'];
$typeOfpurchase = $_POST['typeOfPurchase'];
$Marketing = $_POST['marketing'];
$Field1 = $_POST['input_1'];
$Field2 = $_POST['input_2'];
$Field3 = $_POST['input_3'];
$Field4 = $_POST['input_4'];
$Field5 = $_POST['input_5'];
$Field6 = $_POST['input_6'];
$Field7 = $_POST['input_7'];
$Field8 = $_POST['input_8'];
$Field9 = $_POST['input_9'];
$Field10 = $_POST['input_10'];
$Field11 = $_POST['input_11'];
$Field12 = $_POST['input_12'];
$Field13 = $_POST['input_13'];
$Field14 = $_POST['input_14'];
$Field15 = $_POST['input_15'];
$Field16 = $_POST['input_16'];
$Field17 = $_POST['input_17'];
$message = $_POST['input_18'];
$message = wordwrap($message, 70);
$form_content =
"What Type of Offer: $Offer
If your purhcase was new what was your type of purchase: $typeOfpurchase
Which Marketing Medium: $Marketing
Dealership Name: $Field1
Offer Start Date: $Field2
Offer End Date: $Field3
Year of Vehicle: $Field4
Make of Vehicle: $Field5
Model of Vehicle: $Field6
Trim of Vehicle: $Field7
Model # Vehicle: $Field8
Stock # of Vehicle: $Field9
MSRP of Vehicle: $Field10
Selling Price of Vehicle: $Field11
Down Payment on Vehicle: $Field12
XXX/ Month on Vehicle: $Field13
Last 6 of VIN on Vehicle: $Field14
Rebate on Vehicle: $Field15
APR on Vehicle: $Field16
Residual Payment on Vehicle: $Field17
Other Notes (Rebate Info, Special Details etc): $message";
$email_subject = "Online Offer Submission Form";
$arrEmail = array('Jonathan <myemail@myemail.com?>');
foreach($arrEmail as $key => $email_to)
mail($email_to, $email_subject, $form_content);
header('location: http://www.mydealerworld.com/thank-you-for-contacting-dealer-world/');
}
}
可以使用AJAX请求发送输入值。使用Javascript分配变量后,只需用ajax请求发送它们。(例如varyour_assigned_variable=input.val()
)
$.ajax({
'url':'newformprocess.php',
'type':'post',
'data':{'submit':true,'another_key':your_assigned_variable},
success:function(){
//when successfully sent
},
error:function(){
//if an ajax error occures, do something
}
});
查看更多:
http://api.jquery.com/jquery.ajax/
我正在尝试编写一些相当基本的代码,但多年来没有接触过JavaScript,我真的不确定最好的方法是什么。 目标:有一个42个竞技场部分数字的下拉列表,当选择这些数字时,将根据该数字显示“红色”或“黑色”。为了提供过多信息,部分编号是: 黑色:103, 105, 107, 111, 113, 115, 119, 121, 123, 127, 129, 131, 201, 203, 205, 207,
问题内容: 我遇到一种情况(在硒测试期间),在这种情况下,用户将收到安全代码。然后,用户必须先输入安全密码,然后才能继续操作。 我不太确定如何获得用户输入的值。我浏览了硒文档,并提出了这个建议。不幸的是,它并不是很有效。 有人可以指出我正确的方向吗? 问题答案: 似乎您必须先接受并关闭提示,然后才能存储和使用该值
问题内容: 我有一种情况(在selenium测试期间),在这种情况下,用户将收到安全代码。然后,用户必须先输入安全代码,然后才能继续操作。 我不太确定如何获得用户输入的值。我浏览了selenium文档,并提出了这个建议。不幸的是,它并不是很有效。 有人可以指出我正确的方向吗? 问题答案: 似乎您必须先接受并关闭提示,然后才能存储和使用该值
问题内容: 我试图根据我选择的字段之一的值显示和隐藏一些表单字段。我希望使用数组来保存每个选择值应显示的内容和不应该显示的内容,以免将我从庞大的switch语句中删除,但无法弄清楚该如何做。 我正在使用PHP和jQuery。任何帮助都会很棒。 问题答案: 尝试这样的事情: 然后在jQuery中:
我正在创建具有下拉列表视图的页面。现在我在列表视图中显示完整数据。如果我想要任何特定的日期数据,那么我需要做什么。请帮我解决这个问题。下面是我正在获取的JSON。 下面是代码
问题内容: 我有一个输入字段,如下所示: 我想获取输入字段的值并将其分配给会话。如何使用PHP或jQuery做到这一点? 问题答案: 使用PHP 或超全局变量通过HTML标签的名称来检索输入标签的值。 例如,更改表单中的方法,然后通过输入名称回显该值: 使用方法: 要显示值: 使用方法: 要显示值: