我可以根据下拉选择更改提交操作吗?

时间:2012-05-15 14:36:05

标签: forms submit action selection drop-down-menu

我有一个包含类别和子类别字段以及提交按钮的表单。当用户选择类别然后选择子类别时,他们可以单击提交按钮以根据他们的选择打开网站。我是javascript的新手,无法弄清楚为什么当我传递变量或函数时提交按钮不起作用。我应该先来这里,因为我知道这是专家所居住的地方。这是我的代码 - 我使用通用网站代替我指向的实际网站:

<SCRIPT type=text/javascript> 

function nullOptionsDMA(aMenu){
var tot=aMenu.options.length
for (i=0;i<tot;i++)
{
aMenu.options[i]=null
}
aMenu.options.length=0;
}

/* Category: DOCUMENT CONTROL */
function MySubjectDMA0(aMenu){
nullOptionsDMA(aMenu)
with (aMenu){
options[0]=new Option("--Select a Sub-Category--","none");
options[1]=new Option("Document Review/Change Request","http://www.google.com");
options[2]=new Option("CDD Support","http://www.yahoo.com");
options[0].selected=true
}
}

/* Category: TRAINING */
function MySubjectDMA1(aMenu){
nullOptionsDMA(aMenu) 
with (aMenu){
options[0]=new Option("--Select a Sub-Category--"); 
options[1]=new Option("Training Support","http://www.cnn.com"); 
options[2]=new Option("eUniversity Reports","http://www.wmmr.com"); 
options[3]=new Option("New Hire Orientation","http://www.bbcnews.com");
options[0].selected=true
}
}

/* Category: AUDIT INSPECTION */
function MySubjectDMA2(aMenu){
nullOptionsDMA(aMenu)
with (aMenu){
options[0]=new Option("--Select a Sub-Category--"); 
options[1]=new Option("Audit / Inspection – Info/Doc Request","http://www.abcnews.com");
}
} 

function goDMA(aMenu){
if (aMenu.options.value!="none")
{
location=aMenu.options[aMenu.selectedIndex].value
} 
}

function setUpDMA(){
with (document.formDoubleMenuDMA) {
if (menuSubjectsDMA.selectedIndex==0){
menuSubjectsDMA.options[0].selected=true
menuFilesDMA.options[0].selected=true
}
if (menuSubjectsDMA.selectedIndex==1)
MySubjectDMA0(menuFilesDMA)
if (menuSubjectsDMA.selectedIndex==2)
MySubjectDMA1(menuFilesDMA)
if (menuSubjectsDMA.selectedIndex==3)
MySubjectDMA2(menuFilesDMA)
if (menuSubjectsDMA.selectedIndex==4)
MySubjectDMA3(menuFilesDMA)
}
}

function changeFilesDMA(){
aMenu=document.formDoubleMenuDMA.menuSubjectsDMA
aMenu2=document.formDoubleMenuDMA.menuFilesDMA
with (aMenu){
switch (selectedIndex) {
case 0:
aMenu2.options.length=0;
aMenu2.options[0].selected=true;
history.go(0)
break 
case 1: 
MySubjectDMA0(aMenu2)
break 
case 2: 
MySubjectDMA1(aMenu2)
break 
case 3: 
MySubjectDMA2(aMenu2) 
break 
case 4: 
MySubjectDMA3(aMenu2)
break
}
}
}
</SCRIPT>

<FORM style="WIDTH: 385px; HEIGHT: 210px" name="formDoubleMenuDMA">
<SELECT style="WIDTH: 253px; HEIGHT: 28px" class="style152" onChange="changeFilesDMA()" name="menuSubjectsDMA"> 
<OPTION selected value="none">--Select a Category--</OPTION>
<OPTION>Document Control</OPTION>
<OPTION>Training</OPTION>
<OPTION>Audit Inspection</OPTION></SELECT>
<SELECT style="WIDTH: 252px; HEIGHT: 28px" name="menuFilesDMA">
<OPTION selected value="none">--Select a Sub-Category--</OPTION></SELECT>
<input type="submit" name="mySubmit" value="GO" onClick="changeFilesDMA()">
</FORM>

0 个答案:

没有答案