我有一个HTML表单,根据使用jQuery在第3个下拉列表中选择的内容,动态更新两个下拉列表值。
使用Python(CGI),如何访问两个动态下拉列表中的选定值。
HTML文件:
<body>
<form action="/cgi-bin/ISPsetup.py" method="get" name="theform">
<table cellspacing="20">
<tr>
<td>Site: </td>
<td>
<select id="site">
<option val="va1">va1</option>
<option val="va2">va2</option>
</select>
</td>
</tr>
<tr>
<td>Cap1: </td>
<td>
<select id="cap1">
</select>
</td>
</tr>
<tr>
<td>Cap2: </td>
<td>
<select id="cap2">
</select>
</td>
</tr>
</table>
</form>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript" src="site.js"></script>
</body>
site.js:
va1odd = new Array('va1-isp-cap1-01','va1-isp-cap2-01','va1-rdc-isp-cap3-01','va1-rdc-isp-cap4-01');
va1even = new Array('va1-isp-cap1-02','va1-isp-cap2-02','va1-rdc-isp-cap3-02','va1-rdc-isp-cap4-02');
va2odd = new Array('va2-rdc-isp-cap-01');
va2even = new Array('va2-rdc-isp-cap-02');
populateSelect();
$(function() {
$('#site').change(function(){
populateSelect();
});
});
function populateSelect(){
cat=$('#site').val();
$('#cap1').html('');
$('#cap2').html('');
if(cat=='va1'){
va1odd.forEach(function(t) {
$('#cap1').append('<option>'+t+'</option>');
});
va1even.forEach(function(t) {
$('#cap2').append('<option>'+t+'</option>');
});
}
if(cat=='va2'){
va2odd.forEach(function(t) {
$('#cap1').append('<option>'+t+'</option>');
});
va2even.forEach(function(t) {
$('#cap2').append('<option>'+t+'</option>');
});
}
}
ISPsetup.py:
import cgi, cgitb
# Create instance of FieldStorage
form = cgi.FieldStorage()
site = form.getvlaue('site')