The radio button is disabled first, after the send function is enabled again

I have a jsp where some radio buttons and text boxes depend on 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 in the say element dropdown. 8 or 9 so javascript radio buttons should be disabled for both textboxes and box and button 9. When I select an item it perfectly disables the radio button or textbox radio button but when I submit it shows me the radio button because i came to the same jsp. What is the problem in my javascript?

+3


source to share


2 answers


You should also check the dropdown on the onload event page.

Something like that



<script type="text/javascript">

/**
* This function will be called twice - once on onChage event, and once on onLoad event
*/
    function OnChange() {
    dropdown = document.getElementById('myDropDown');
        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) {
            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>

<body onload="OnChange()">
<s:form action="crInquiry" name="form">    
            <s:select name="filterValue" list="headerList" id="myDropDown"
    onchange="OnChange();" />
            <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>

      

+2


source


If I understood your problem correctly, I think there is no problem with your Javascript.
Because there is no relationship between the pre-submission page data and after submission it will create a problem.

You can overcome this problem in one of the following ways. 1. Name your javascript on the "OnLoad" event of the body and it will work the same for you.
2. Save the current state of the page in some control (for example, text fields) and send it with other page data. At load time (maybe onLoad or at the end of your JSP page) you can restore the state using the value in this field.



I hope this works for you.

+1


source







All Articles