Php 当用户选择其他选项时添加另一个文本框
我的表格是这样的Php 当用户选择其他选项时添加另一个文本框,php,mysql,Php,Mysql,我的表格是这样的 <form action="add_customers.php" method="post" onsubmit="MM_validateForm('name','','R','passport_no','','R','remarks','','R');return document.MM_returnValue"> <tr> <td>Name of the Applicant:</td> <
<form action="add_customers.php" method="post" onsubmit="MM_validateForm('name','','R','passport_no','','R','remarks','','R');return document.MM_returnValue">
<tr>
<td>Name of the Applicant:</td>
<td><label for="name"></label>
<input type="text" name="name" id="name" /></td>
</tr>
<tr>
<td>Country applying for :</td>
<td><label for="country"></label>
<select name="country" id="country">
<option>Singapore</option>
<option>Malaysia</option>
<option>Istanbul</option>
<option>Thailand</option>
<option>China</option>
<option>Other</option>
</select></td>
</tr>
<tr>
<td>Visa Categeory :</td>
<td><label for="visa_categeory"></label>
<select name="visa_categeory" id="visa_categeory">
<option>Visit</option>
<option>Business</option>
<option>Other</option>
</select></td>
</tr>
<tr>
<td>Passport No:</td>
<td><input type="text" name="passport_no" id="passport_no" /></td>
</tr>
<tr>
<td>Remarks:</td>
<td><label for="remarks"></label>
<textarea name="remarks" id="remarks" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" id="submit" value="Submit" /></td>
</tr></form>
申请人姓名:
申请国家:
新加坡
马来西亚
伊斯坦布尔
泰国
中国
其他
Visa类别:
参观
生意
其他
护照号码:
评论:
现在我的问题是
1) 当用户从Visa类别中选择其他选项时,会自动为用户显示一个文本框,并捕获他输入的内容。
2) 将详细信息保存到mysql数据库中
使用的语言有PHP、MYSQL
谢谢。您可以在表单中添加一个文本框,并在第一时间将其隐藏。
使用javascript更改您提到的下拉列表时,使文本框可见。
您可以在接受数据的页面中获取文本框的值,并将其与其他变量一起插入add_customers.php中的数据数据库
<script>
function visacatOnchange(){
var visa_cat = document.getElementById('visa_categeory').value
if(visa_cat == "Visit")
document.getElementById("new_textbox").style.display="block";
else
document.getElementById("new_textbox").style.display="none";
}
</script>
功能内窥镜改变(){
var visa_cat=document.getElementById('visa_category')。值
如果(签证类别=“访问”)
document.getElementById(“新建文本框”).style.display=“块”;
其他的
document.getElementById(“新建文本框”).style.display=“无”;
}
以html格式添加
<input type="text" name="new_textbox" id="new_textbox" style="display:none;">
改变
<select name="visa_categeory" id="visa_categeory" onChange="visacatOnchange();">
祝您好运:-)最初,您可以隐藏文本框div,然后在选择输入的“onchange”事件中显示它
<div id="textboxdiv" style="visibility: hidden">
Visa Option <input type="text" id="someid"/>
</div>
<select name="visa_categeory" id="visa_categeory" onchange="showTextBox()" >
<option>Visit</option>
<option>Business</option>
<option value="99" >Other</option>
</select>
下面是一些基本的JavaScript/jQuery,可以帮助您解决第一个问题: HTML
参观
生意
其他
JS
$('select')。更改(函数(){
var$selected=$('select option:selected');
如果('Other'=$selected.text()){
$('form').append($('').prop({'type':'text','id':'visa_other','name':'visa_other'});
$('form').append($('').prop({'for':'visa_other'}).html('Testing');
}否则{
$('input').remove();
$('label').remove();
}
});
如果选择了“其他”选项,则上述代码将仅显示一个文本框(以及附带的标签),如果随后选择了其他选项,则将删除该文本框
希望有帮助 您需要
javascript
来显示新的文本字段,并且根据您的输入,您应该能够知道如何插入新数据。但是如果你发布你的SQL
,它会有所帮助。
function showTextBox(){
if ($('#visa_categeory').val() == '99') {
$('#textboxdiv').css({'visibility':'visible'});
}
<form>
<select name="visa_category">
<option>Visit</option>
<option>Business</option>
<option>Other</option>
</select>
</form>
$('select').change(function() {
var $selected = $('select option:selected');
if ('Other' === $selected.text()) {
$('form').append($('<input>').prop({'type':'text','id':'visa_other','name':'visa_other'}));
$('form').append($('<label>').prop({'for':'visa_other'}).html('Testing'));
} else {
$('input').remove();
$('label').remove();
}
});