2012-03-27 104 views
1

我使用以下function of javascript來啓用和禁用radio buttonstextbox隨着drop down的值更改。
它在開始時很好,但是當我點擊提交按鈕時,如果myindex = 8 or 9在提交時不起作用。
此時radio button filter[0] and filter[1]應該被禁用,並且textfield count應該被啓用我在選擇下拉菜單並同時點擊提交按鈕時調用了這個函數。
我不知道它爲什麼不工作。任何幫助。javascript的功能第二次不工作

function OnChange(dropdown) { 
    var myindex = dropdown.selectedIndex; 

    document.form.filter[0].disabled = false; 
    document.form.filter[1].disabled = false; 

    if (myindex == 8) { 
     document.form.filter[0].disabled = true; 
     document.form.filter[1].disabled = true; 
     document.form.count.disabled = false; 
     document.form.submit.disabled = false; 
    } else if (myindex == 9) { 
     alert("in ALL"); 
     document.form.filter[0].disabled = true; 
     document.form.filter[1].disabled = true; 
     document.form.count.disabled = true; 
     document.form.submit.disabled = false; 

     alert(document.form.filter[0].disabled); 
    } 

    else { 
     document.form.filter[0].disabled = false; 
     document.form.filter[1].disabled = false; 
     document.form.count.disabled = true; 
     document.form.submit.disabled = false; 
    } 
} 

這是我的HTML代碼如下。

<s:form action="crInquiry" name="form" > 
    <table align="center" width="1020"> 
     <tr> 
      <td>Batch Id : <s:property value="batchId" /> 
       <fieldset 
        style="background-color: #F7F9F3; margin: 2px; padding: 8px; -moz-border-radius: 5pt; border: 1px solid #A7CBE3;"> 
        <legend class="field_label"> 
         <strong>Inquiry Log Status</strong> 
        </legend> 
        <table border="0" id="main_table1" cellpadding="5" width="1010" 
         cellspacing="5" align="center"> 
         <tr style="height: 5px;"> 
          <td width="300" height="2" align="left" colspan="0"><s:hidden 
            name="batchId" id="batchId" 
            onfocus="OnChange((this.form.filterValue));" 
            value="%{ batchId }"></s:hidden> <s:select 
            cssClass="bulkSelect" name="filterValue" 
            label="Search Criteria" required="true" theme="css_xhtml" 
            labelposition="bottom" tabindex="2" list="headerList" 
            onchange="OnChange(this.form.filterValue);" /> 
          </td> 


          <td width="180"><s:radio name="filter" 
            requiredposition="right" 
            list="#{'STATUS_FILTER_START':'START','STATUS_FILTER_END':'END'}" 
            label="Stage" labelposition="right" theme="css_xhtml" 
            tabindex="9" labelposition="bottom"></s:radio> 
          </td> 
          <td width="50" height="2"><s:textfield disabled="true" 
            value="0" name="count" size="2" labelposition="1" 
            theme="css_xhtml"></s:textfield> 
          </td> 
          <td width="180"><s:radio name="order" 
            requiredposition="right" list="#{'ASC':'ASC','DESC':'DESC'}" 
            label="Order" labelposition="right" theme="css_xhtml" 
            tabindex="9" labelposition="bottom"></s:radio> 
          </td> 
          </td> 


          <td width="50"><s:submit theme="css_xhtml" value="Filter" 
            align="left" onclick="gotopage('FilteredInquiryLog');"></s:submit> 
          </td> 
          <td width="59"><s:submit theme="css_xhtml" value="Details" 
            onclick="gotopage('crInquiry')"></s:submit></td> 

         </tr> 


        </table> 
       </fieldset> 
      </td> 
     </tr> 

    </table> 
</s:form> 

,並從提交我稱之爲從那裏調用上面的js函數的js函數

function gotopage(actionname) { 
     document.form.action = actionname + ".action"; 
     document.form.submit(); 
     OnChange(document.form.filterValue); 

    } 
+1

請顯示相關的HTML並顯示從提交操作中調用此函數的代碼。 – jfriend00 2012-03-27 05:09:54

+0

@Nivesh:你怎麼可能認爲這是足夠的信息讓別人能夠幫助你? – bernie 2012-03-27 05:12:35

+0

@bernie請原諒,我剛剛添加了相關的代碼 – 2012-03-27 05:16:07

回答

0

這似乎很奇怪,你會提交表單,然後試圖操縱等領域...

function gotopage(actionname) { 
     document.form.action = actionname + ".action"; 
     document.form.submit(); 
     OnChange(document.form.filterValue); 

    } 

或許你需要的是:

function gotopage(actionname) { 
     OnChange(document.form.filterValue); 

     document.form.action = actionname + ".action"; 
     document.form.submit(); 
    }