简体   繁体   中英

Show a hidden div on page load


I have a tr like this in my jsp.

<tr id = "fromDate" style="display:none;">

I also have a select like this.

    <select id="select2" name="dateRange1" 
               onChange="javascript:chooseDate(this.value);">
    <option value="0" <c:if test='${dateRange == 0}'> 
            selected </c:if>>Select a Date</option>

The javascript function used in the select is as below.

function chooseDate(val) {
        if (val == "0") { 
            document.getElementById("fromDate").style.display='';
            }
        else 
        {
            document.getElementById("fromDate").style.display='none';
        }
    }

So if the selected row is not 0, i wont be displaying the tr in the page. This is working fine.
I set the dateRange variable in request.setAttribute() and sending it from action.
The problem is the option is selected properly from the request value, but the tr is not shown
I tried running it like this outside the form in jsp, hoping that it will get executed before the page load, but didn't happen.

<script language="javascript">
   chooseDate(${dateRange});
</script>

Any thoughts?

Try this!

<script language="javascript">
   window.onload = function() {
      chooseDate(${dateRange});
   }
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM