![](/img/trans.png)
[英]Populate drop down list from another drop down list in php and javascript
[英]Populate drop down list dynamically from .txt file via .php
我在發布之前進行了搜索,但一直在努力尋找解決以下問題的方法。
我已經構建了一個 HTML 表單(帶有表單構建器)並且需要將一個頁面中的信息獲取到下一頁的下拉框中,第一頁上的輸入包括用戶將輸入的六個級別的工資率。 然后,我需要將這些工資率放入第 2 頁的下拉列表中,以用於該頁面的計算。 我遇到了一些腳本,但他們似乎需要從數據庫或文本文件中提取信息,在我的項目中,我沒有,只有鏈接到 .txt 模板的 .php 文件框中的實時數據。 即 1.php 頁面由 6 個 txt 文件填充,當您單擊表單頁面時。 任何人都可以建議這樣做的方法嗎? 該頁面確實包含以下腳本;
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<!--script src='scripts/jquery-1.7.2.min.js' type='text/javascript'></script>
<!--script src='scripts/globalize.js' type='text/javascript'></script>
<script src='scripts/jquery.sim.number.js' type='text/javascript'></script>
<script src='scripts/jquery.sim.utils.js' type='text/javascript'></script>
如果我正確理解了這個問題,那么您需要的是
第 1 頁
<html>
<head></head>
<body>
<form action ="a.html" method
= "get" name = "payrate" id =
"payrate"> Payrate
<br/>
Level 1
<input type = "text" name =
"field1" id = "field1" />
<br/>
Level 2
<input type = "text" name =
"field1" id = "field1" />
<br/>
Level 3
<input type = "text" name =
"field1" id = "field1" />
<br/>
Level 4
<input type = "text" name =
"field1" id = "field1" />
<br/>
Level 5
<input type = "text" name =
"field1" id = "field1" />
<br/>
Level 6
<input type = "text" name =
"field1" id = "field1" />
<br/>
<input type = "submit"/>
</form>
</body>
</html>
第2頁
<body>
<div>
<select>
<option class = 'dropdown'>
</option>
<option class = 'dropdown'>
</option>
<option class = 'dropdown'>
</option>
<option class = 'dropdown'>
</option>
<option class = 'dropdown'>
</option>
<option class = 'dropdown'>
</option>
</select>
</div>
<script>
//get the value of each field
from the url as a query string
var query = location.search;
var splitQuery = []; var value
= [];
function parseQuery(query){
/*check if there are
mutiple value (querystring in
url are seperated with &), and
store them to an associative
array*/
if(query.search(/[&]/)){
splitQuery = query.split('&');
/*split again and target drop
down*/
for (var x = 0; x <
splitQuery.length; x++){
var splitEach =
splitQuery[x].split('=');
document.getElementsByClassName
('dropdown')[x].textContent =
splitEach[1];
}
}
}
parseQuery(query);
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.