[爆卦]javascript下拉式選單取值是什麼?優點缺點精華區懶人包

為什麼這篇javascript下拉式選單取值鄉民發文收入到精華區:因為在javascript下拉式選單取值這個討論話題中,有許多相關的文章在討論,這篇最有參考價值!作者vampire1128 (吸血鬼)看板Ajax標題[問題] javascript 三層下拉選單請...


我是剛接觸javascript的新人
一直對於javascript指令實在是摸不透

最近使用javascript來寫動態三層下拉選單
目前我已經做出三層式下拉選單成功了
並將選單選擇的VALUE傳送到資料庫儲存

希望下一次要修改這一筆資料時
三層下拉選單可以直接選好前一次的選項

我想要請教的是
1.以我已下程式的寫法為例,
叫出前一次資料時javascript自動選取前一次選項的寫法。

2.以我已下程式的寫法為例,
我原本是想透過比對資料庫與選項value值來選取,
javascript要如何讀取到value呢?
或者是有其他更好的方法可以意見提供呢?
在html有寫到this.options.selectedIndex不知道也是可以用此數值來判斷?
那寫法如何?

完整呈是請參考此網頁
http://big5.webasp.net/javascript/1/282.htm
方法我有略改(選項資料都是寫在資料庫用迴圈去跑)
但是是使用這個網頁的原理

感激好心人的解答

以下是
html=======================================================================

<FORM name="isc">

<!--第一層選單 選項資料都是寫在資料庫用迴圈去跑,在此先以幾筆資料替代-->
<select name="example" size="1"
onChange="redirect(this.options.selectedIndex)">
<option selected>---Select1-------------</option>
<option>Webmaster Sites</option>
<option>News Sites</option>
</select>

<!--第二層選單 選項資料都是寫在資料庫用迴圈去跑,在此先以幾筆資料替代-->
<select name="stage2" size="1"
onChange="redirect1(this.options.selectedIndex)">
<option value=" " selected> </option>
<option value=" " selected>---Select2--------------</option>
</select>

<!--第三層選單 選項資料都是寫在資料庫用迴圈去跑,在此先以幾筆資料替代-->
<select name="stage3" size="1"
onChange="redirect2(this.options.selectedIndex)">
<option value=" " selected> </option>
<option value=" " selected>---Select3----------------</option>
</select>

</form>

以下是
javascript==================================================================

<script language="JavaScript" >

<!--第二層選單寫法 已將選項寫進資料庫去跑迴圈-->

var groups=document.isc.example.options.length
var group=new Array(groups)
for (i=0; i<groups; i++)
group[i]=new Array()

group[1][0]=new Option('請選擇',' ');
.
.
.

.
.
.
var temp=document.isc.stage2
function redirect(x){
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null
for (i=0;i<group[x].length;i++){
temp.options[i]=new Option(group[x][i].text,group[x][i].value)
}
temp.options[0].selected=true
redirect1(0)

<!--第三層選單寫法 已將選項寫進資料庫去跑迴圈-->

var secondGroups=document.isc.stage2.options.length
var secondGroup=new Array(groups)
for (i=0; i<groups; i++) {
secondGroup[i]=new Array(group[i].length)
for (j=0; j<group[i].length; j++) {
secondGroup[i][j]=new Array() }}

secondGroup[0][0][0]=new Option("---Select 3---"," ");
.
.
.

.
.
.
var temp1=document.isc.stage3
function redirect1(y){
for (m=temp1.options.length-1;m>0;m--)
temp1.options[m]=null
for
(i=0;i<secondGroup[document.isc.example.options.selectedIndex][y].length;i++){
temp1.options[i]=new
Option(secondGroup[document.isc.example.options.selectedIndex][y][i].text,secondGroup[document.isc.example.options.selectedIndex][y][i].value)
}
temp1.options[0].selected=true
}

function redirect2(z){
window.location=temp1[z].value
}
</script>

請教ptt高手解答
感激

--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 222.156.238.216
※ 編輯: vampire1128 來自: 222.156.238.216 (11/02 02:09)
superGA:ppt高手 是很會作power point的高手嗎 XD 11/02 09:27
※ 編輯: vampire1128 來自: 222.156.238.216 (11/02 10:18)
vampire1128:感謝提醒 11/02 10:23

你可能也想看看

搜尋相關網站