asp code

2007-04-19 11:09 pm
我想問下用咩code可以寫到以下既野
1.當我改左一個text field or select field 入面既野
另一個select field入面既option會改變?
例如變成第一個text field or select field入面既野
2.點先可以tick左一個radio button 佢就唔比人入野落個text field
tick另一個就比佢入?
3. 點先可以唔駛submit就check到一個text field入面有冇野而且彈個警告出黎?

以上既情況我係想唔駛submit既情況下進行
即係好似yahoo知識問問題果時下面果個問題分類咁
更新1:

仲有d想問 條題目嚮http://hk.knowledge.yahoo.com/question/?qid=7007041901721 都係40分

更新2:

haha 因為我對jave script識既野仲皮毛過vb,所以如果有多d例子我會好感激~

回答 (2)

2007-04-21 10:48 am
✔ 最佳答案
(1)
The javascript section

var options0 = new Array('A', 'B', 'C');
var options1 = new Array('D', 'E', 'F');

function changeOptions(index)
{
// remove option list in select
var select1 = document.getElementById("Select1");
var size = select1.length;
for (var i = size-1; i >= 0; i--)
select1.remove(i);
// populate option list
if (index == 0) {
size = options0.length;
for (var i = 0; i < size; i++)
addItem(select1, options0[i]);
}
else if (index == 1) {
size = options1.length
for (var i = 0; i < size; i++)
addItem(select1, options1[i]);
}
}

function addItem(select1, val)
{
var oOption = new Option(val, val);
select1.options.add(oOption);
}

function checkField()
{
var field1 = document.getElementById("Field1");
if (!field1.value.length) {
alert('Field1 is blank.');
return false;
}
else
return true;
}

The html section

<input type="select" id="Select2" name="Select2" onchange="changeOptions(this.selectedIndex)" ]
<option ]One
<options ]Two

<input type="select" id="Select1" name="Select1" ]

(2)
<input type="radio" name="Radio1" onclick="this.form.Field1.disabled = true" ]
<input type="radio" name="Radio1" onclick="this.form.Field1.disabled = false" ]
<input type="text" id="Field1" name="Field1" ]

(3)
<input type="submit" onclick="return checkField()" ]

Replace ] closing tag >
2007-04-20 12:07 am
你都識講係唔駛submit o既情況下進行, 用javascript啦
睇你問得呢o的o野都知你識寫program, 唔駛俾source code你啦
大致idea係用onChange event同disabled property
下面兩個url有晒解釋同example
http://www.w3schools.com/jsref/jsref_onchange.asp
http://www.quirksmode.org/js/disabled.html


收錄日期: 2021-04-25 20:32:48
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20070419000051KK01736

檢視 Wayback Machine 備份