我正在使用以下代码制作联系表格
<?php
$action = $_SERVER['PHP_SELF'];
$fname = $_POST['fname'];
$phone = $_POST['phone'];
$e_mail = $_POST['e_mail'];
$service = $_POST['service'];
$maker = $_POST['maker'];
$model = $_POST['model'];
$year = $_POST['year'];
$message = $_POST['message'];
$headers = 'From: me <reply@locallockman.com>';
$thankyou = "thankyou.html"; // thank you page
if(isset($_POST['fname']) && isset($_POST['phone']) && isset($_POST['e_mail']) && isset($_POST['service']) && isset($_POST['maker']) && isset($_POST['model']) && isset($_POST['year']) && isset($_POST['message'])){
$fname = $_POST['fname'];
$phone = $_POST['phone'];
$e_mail = $_POST['e_mail'];
$type = $_POST['service'];
$maker = $_POST['maker'];
$model = $_POST['model'];
$year = $_POST['year'];
$message = $_POST['message'];
if(empty($phone)){
echo 'Please fill all fields.';
}
else{
if(mail($to,$subject,$body,$headers)){
header('Location: thankyou.html');
}
else{
echo 'There was an error sending email/s.';
}
}
}
?>
它工作得很好,但我希望在用户选择另一个选项时禁用文本字段。我为此使用javascript。这是代码
<script>
function findselected(){
var state = document.getElementById('#type');
var notus = document.getElementById('#model');
var year = document.getElementById('#year');
var maker = document.getElementById('#maker');
(state.value == "Automotive Service")? notus.disabled = false : notus.disabled = true;
(state.value == "Automotive Service")? year.disabled = false : year.disabled = true;
(state.value == "Automotive Service")? maker.disabled = false : maker.disabled = true;
}
</script>
这是html代码
<select name="service" id="type" onchange="findselected()">
<option value="Not Selected">Select Service Type</option>
<option value="Residential Service">Residential Service</option>
<option value="Commercial Service">Commercial Service</option>
<option value="Industrial Service">Industrial Service</option>
<option value="24/7 or Emergency Service">24/7 or Emergency Service</option>
<option value="Automotive Service">Automotive Service</option>
</select>
<select name="maker" id="maker" disabled="disabled" style="margin-left:36px;" autocomplete="on">
<option value="Not Selected" selected="selected" ><strong>Select Car Make</strong></option>
<option value="Acura" >Acura</option>
<option value="Audi">Audi</option>
<option value="BMW">BMW</option>
<option value="Buick">Buick</option>
<option value="Cadillac">Cadillac</option>
<option value="Chevrolet">Chevrolet</option>
<option value="Chrysler">Chrysler</option>
<option value="Daewoo">Daewoo</option>
<option value="Dodge">Dodge</option>
<option value="Fiat">Fiat</option>
<option value="Ford">Ford</option>
<option value="General Motors">General Motors</option>
<option value="Honda">Honda</option>
<option value="Hummer">Hummer</option>
<option value="Hyundai">Hyundai</option>
<option value="Isuzu">Isuzu</option>
<option value="Infinity">Infinity</option>
<option value="Jaguar">Jaguar</option>
<option value="Jeep">Jeep</option>
<option value="Kia">Kia</option>
<option value="Lexus">Lexus</option>
<option value="Lincoln">Lincoln</option>
<option value="Mercedes">Mercedes Benz</option>
<option value="Mazda">Mazda</option>
<option value="Mercury">Mercury</option>
<option value="Mini">Mini</option>
<option value="Mitsubishi">Mitsubishi</option>
<option value="NISSAN">NISSAN</option>
<option value="Plymouth">Plymouth</option>
<option value="Pontiac">Pontiac</option>
<option value="Porche">Porche</option>
<option value="Saab">Saab</option>
<option value="Saturn">Saturn</option>
<option value="Subaru">Subaru</option>
<option value="Suzuki">Suzuki</option>
<option value="Toyota">Toyota</option>
<option value="Volkswagen">Volkswagen</option>
<option value="Volvo">Volvo</option>
</select>
<input type="text" name="model" id="model" style="margin-left:83px;" class="text-box" autocomplete="on" disabled="disabled" value=" "/><br /><br />
Model Year:
<input type="text" name="year" id="year" value=" " disabled="disabled" style="margin-left:73px;" class="text-box" autocomplete="on"/>
这是完整的代码。我希望当我在标签中选择任何其他选项然后“汽车服务”时,名称为“年份”、“型号”的字段和名称为“制造商”的列表框应该被禁用,并且应该将空白值发送到电子邮件。
这对我有用,但是当我运行它时,表单不起作用。当我选择汽车服务时,表单工作和文本字段“年份”和“模型”被启用并且表单工作。但是当我从该字段中选择任何其他选项并且文本字段被禁用时,表单不起作用,我该如何解决它,请帮忙。
请让我知道,如果你有任何问题。