0
我正在設計一個允許用戶查詢xml
文件的HTML
網頁。基本上,他們選擇他們想要查詢的列,搜索類型,然後鍵入他們的值。但是,如果他們在組合框中進行選擇,那麼在第一個文本輸入框之後,我想要一個&標籤,並出現另一個輸入框。基於組合框選擇更改HTML佈局
當前的代碼如下:
<form name="myform" action="podcatalog.xml" method="POST">
<select id="ddl" onchange="configureDropDownLists(this,'ddl2')">
<option value="author">Author</option>
<option value="title">Title</option>
<option value="pages">Pages</option>
<option value="year">Year</option>
</select>
<select id="ddl2" onchange="configureTextFields(this, 'querystring')">
</select>
<input type="text" name="querystring"/>
<input type="submit" value="Search"/>
</form>
<script type="text/javascript">
function configureDropDownLists(ddl1,ddl2) {
var string = new Array('Contains', 'Equals');
var number = new Array('=', '<', '>', 'Between', '!=');
switch (ddl1.value) {
case 'author':
document.getElementById(ddl2).options.length = 0;
for (i = 0; i < string.length; i++) {
createOption(document.getElementById(ddl2), string[i], string[i]);
}
break;
case 'title':
document.getElementById(ddl2).options.length = 0;
for (i = 0; i < string.length; i++) {
createOption(document.getElementById(ddl2), string[i], string[i]);
}
break;
case 'pages':
document.getElementById(ddl2).options.length = 0;
for (i = 0; i < number.length; i++) {
createOption(document.getElementById(ddl2), number[i], number[i]);
}
break;
case 'year':
document.getElementById(ddl2).options.length = 0;
for (i = 0; i < number.length; i++) {
createOption(document.getElementById(ddl2), number[i], number[i]);
}
break;
default:
document.getElementById(ddl2).options.length = 0;
break;
}
}
function createOption(ddl, text, value) {
var opt = document.createElement('option');
opt.value = value;
opt.text = text;
ddl.options.add(opt);
}
function configureTextFields(ddl2) {
switch (ddl2.value) {
case 'Between':
// Need code here?