gpt4 book ai didi

javascript - 根据选择值存储表单输入字段?

转载 作者:行者123 更新时间:2023-11-28 06:48:29 25 4
gpt4 key购买 nike

每当用户访问注册页面并选择他的大学但没有找到他的大学时,就会出现“其他”选项...

当他点击“其他”时,会显示另一个输入字段,说明指定您的大学现在的问题是我不想在数据库中存储“其他”值如果他从选择选项中选择他的大学,那么应该插入该值,但如果他选择“其他”选项,那么他在“指定”输入中写入的值应该存储在数据库中

这是我的代码

   <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
}
?>

关于javascript - 根据选择值存储表单输入字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33193919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com