2013-01-21 46 views
0
「沒有定義」 警告

我有以下的javascript代碼,它的工作,但內螢火蟲它說Javascript代碼的工作,但在Firebug

document.form1.element [i]不定義

,然後它工作正常

function set_action(){ 

for (var i=0;i<=3;i++) 
{ 

    if (document.form1.PayType[i].checked == true) 

     { 
      var billerid = document.form1.billerid[i].value; 
          document.form1.action = billerid +"_mypag.htm"; 
     } 
} 

和我的HTML標記如下

<form name="form1" action="..."> 
<input name="PayType" type="radio" value="0" id="ultipay" class="radiobtn" checked/> 
<select name="billerid" class="dropbox"> 
<option>item1</Option>... 
</select> 
<input name="PayType" type="radio" value="1" id="ultipay" class="radiobtn"/> 
<select name="billerid" class="dropbox"> 
<option>item1</Option> 
</select> 
<input name="PayType" type="radio" value="2" id="ultipay" class="radiobtn"/> 
<select name="billerid" class="dropbox"> 
<option>item1</Option>... 
</select> 
<input name="PayType" type="radio" value="3" id="ultipay" class="radiobtn"/> 
<select name="billerid" class="dropbox"> 
<option>item1</Option>... 
</select> 
<input type="button" onclick="set_action()" value="submit"> 
</form> 

我不知道爲什麼我得到這個錯誤。

+0

更改表單1以形成hml和js ..然後檢查 –

+3

不,爲什麼他應該這樣做?那是他的形式的名字! – hereandnow78

+2

你只有4個元素,但迭代7(或更糟糕的是,8,謝謝@Marcel)? – Bergi

回答

2

如果您只有一個單選按鈕名稱PayType,那麼您需要使用document.form1.PayType來解決它。如果存在具有相同名稱的多個單選按鈕,則將其作爲數組進行尋址。例如:

<input name="PayType" type="radio" value="0" id="ultipay0" class="radiobtn" checked="checked" /> 
<input name="PayType" type="radio" value="1" id="ultipay1" class="radiobtn" /> 
相關問題