[英]How to show form input fields based on select value in html/JavaScript?
[英]Store form input fields based on select value?
每當用戶訪問注冊頁面時,以及當他選擇自己的大學但未找到他的大學時,都有“其他”選項...
當他單擊“其他”時,將顯示另一個輸入字段,指出要指定您的大學。現在的問題是,如果他從選擇選項中選擇他的大學,那么我不想在數據庫中存儲“其他”值,則應該插入該值,但是如果他選擇“其他”選項,那么他在“指定”輸入中寫入的值應存儲在數據庫中
這是我的代碼
<select class="job-purpose" name="college" id="college" >
<option selected="selected" value="">-</option>
<option value="1">
NID - National Institute Of Design</option>
<option value="2">
NIFT - National Institute Of fashion Technology</option>
<option value="3">
Pearl Academy Of Fashion</option>
<option value="4">
SOFT - School Of Fashion Technology</option>
<option value="5">
Srishti Institute Of Design</option>
<option value="6">
MITID</option>
<option value="7">
Arch Academy Of Design</option>
<option value="8">
Satyam Fashion Institute</option>
<option value="9">
NIIFT</option>
<option value="10">
UID - United World Institute Of Design</option>
<option value="11">
International College Of Fashion </option>
<option value="12">
Raffles</option>
<option value="other">
other</option>
</select>
這是更改選項代碼
<div class="form-group" style="display:none;" id="coll">
<div class="col-md-12">
<div class="label-wrapper">
<label class="control-label">College <span
class="vd_red">*</span></label>
</div>
<input type="text" name="coll" id="col"
placeholder="College Name">
</div>
</div>
這是Javascript代碼
< script type="text/javascript" >
$('#college').change(function(){
selection = $(this).val();
switch(selection)
{
case 'other':
$('#coll').show();
break;
default:
$('#coll').hide();
break;
}
});
< /script >
PHP部分
if(empty($looking)or empty($profession) or empty($experience)or
empty($current)or empty($state)or empty($jobtype)or empty($about)){
if($college == 'others'){
$coll= $_POST['coll'];
unset($_POST['college']);
$college= $coll;
}
<?php
$college = $_POST['college'];
$coll = $_POST['coll'];
//this below line checks for is college selected and checks for the value selected not the "other" option
if (isset($collage) && $collage != 'other') {
//run your database query hear
}elseif (isset($coll)) { //this line checks for the inputfiled coll isset if yes go to next line
//run your database query hear
}
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.