我在我的项目中使用了struts框架。已在我的JSP上使用了一个复选框,一个按钮和一个文本框。以下是所有这些代码。Struts - JSP - 使用Java脚本启用/禁用基于状态复选框的按钮和文本框
<html:text name="FormBean" styleId = "codeERText" property="codeER" onFocus="change_classe_byId(this,'on');" onBlur="change_classe_byId(this,'off');" styleClass="off" maxlength="5"/>
<input type="button" styleId = "deduireButton" name = "deduireButton" id = "deduireButton" value="<bean:message key="Property.deduire"/>" onClick="javascript:validate('DEDUIRE');">
<html:checkbox styleId="idBrodcastCheckbox" property="sentToAll" name="FormBean" onChange="javascript:broadcastValidate();" />
要求是当复选框被选中时,它应该禁用按钮和文本框,反之亦然。
以下是在复选框的onChange事件中调用的函数.. 在Application上运行时,它只是给出第一个警报(“Inside Broadcast Validate”)..没有其他警报提出。或文本框被禁用。我相信,它不会进入任何If/Else对。
使用的App Server是Weblogic 8.1。
function broadcastValidate(){
alert("Inside Broadcast Validate");
if(document.forms[0].idBrodcastCheckbox.checked == true)
{
alert("checked true");
document.forms[0].codeERText.disabled = true;
document.forms[0].deduireButton.disabled = true;
}
else
{
alert("checked false");
document.forms[0].codeERText.disabled = false;
document.forms[0].deduireButton.disabled = false;
}
alert("First If over");
if(this.document.FormBean.getElementById("idBrodcastCheckbox").checked == true)
{
alert("checked true 2");
this.document.getElementById("codeERText").disabled = true;
this.document.getElementById("deduireButton").disabled = true;
}
else
{
alert("checked false 2");
this.document.getElementById("codeERText").disabled = false;
this.document.getElementById("deduireButton").disabled = false;
}
alert("Second If over ");
if(document.forms[0].sentToAll.value == true)
{
alert("checked true - Sent to All");
document.forms[0].codeERText.disabled = true;
document.forms[0].deduireButton.disabled = true;
}
else
{
alert("checked false - Sent to All");
document.forms[0].codeERText.disabled = false;
document.forms[0].deduireButton.disabled = false;
}
alert("Third If over - Exiting Broadcast Validate");
}
请对此建议一些解决方案。
谢谢戴夫..我修改了代码,并使用document.getElementById('idBrodcastCheckbox') 建议。它现在工作正常..非常感谢:) –
@NiravKhandhedia真棒,很高兴你得到它的工作! –