I have a jsp where some radio buttons and textboxes depend on dropdown selection.
Here is my jsp and javascript code.
jsp
<s:form action="crInquiry" name="form">
<s:select name="filterValue" list="headerList"
onchange="OnChange(this.form.filterValue);" />
<s:radio name="filter" list="#{'STATUS_FILTER_START':'START','STATUS_FILTER_END':'STOP'}"
label="Stage"></s:radio>
<s:textfield disabled="true" value="0" name="count" theme="css_xhtml"></s:textfield>
<s:radio name="ascOrder" list="#{'ASC':'ASC','DESC':'DESC'}"></s:radio>
<s:submit value="Filter" onclick="gotopage('FilteredInquiryLog')"></s:submit>
<s:submitvalue="Details" onclick="gotopage('crInquiry')"></s:submit>
</s:form>
javascript
<script type="text/javascript">
function OnChange(dropdown) {
var myindex = dropdown.selectedIndex;
document.form.filter[0].disabled = false;
document.form.filter[1].disabled = false;
if (myindex == 8) {
alert("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("9");
document.form.filter[0].disabled = true;
document.form.filter[1].disabled = true;
document.form.count.disabled = true;
document.form.submit.disabled = false;
}
else{
document.form.filter[0].disabled = false;
document.form.filter[1].disabled = false;
document.form.count.disabled = true;
document.form.submit.disabled = false;
}
}
function gotopage(actionname)
{
document.form.action=actionname+".action";
document.form.submit();
}
</script>
The problem is when I select an item on dropdown say element no. 8 or 9 so by javascript radio buttons should be disabled for both and textfield and radio button for 9.
When I select an item it disabled dependent radion button or textfield perfectly but when I submit, it show me the radio button enabled because I come to the same jsp.
What is the problem in my javascript?
You should check your dropdown value also on page onload event.
Something like this