0

My current code looks like this:

@if(IsPost)
            {
               <input class="form-control" type="date" id="selDay" name="selDay" value="@(Request.Form["selDay"])" />
            }
            else
            {
                <input class="form-control" type="date" id="selDay" name="selDay" />
            }

When I insert a breakpoint and check the value being passed, it is correct. The selected date is passed as the value for the input, but it is not being saved. The default value is today's date (when the page loads for first time). Even after submit, the date shows as today's date.

I also tried

value="javascript:keepDate();"

<script>
function keepDate() {
 var date = document.getElementById("selDay");
 return date.value;
}
</script>

I want to retain the selected date after the page reloads, and keep that selected date. I'm using asp.net mvc4 if that matters.

*I don't need to retain the its value when it is disabled and has default value. I only need this when it is enabled and the user changes the date (I need to retain the new changed date.)

Bivo Kasaju
  • 1,143
  • 3
  • 13
  • 28
  • Possible duplicate of [Disabled form inputs do not appear in the request](http://stackoverflow.com/questions/7357256/disabled-form-inputs-do-not-appear-in-the-request) – Albireo Mar 09 '16 at 14:10
  • Removed the "disabled" section, has nothing to do with that. – Bivo Kasaju Mar 09 '16 at 14:12

2 Answers2

0

If you want to value stay in browser after user submit the form, you should consider to use cookie to store that val.

Other way is to use ASP to send back your value to browser when form is submitted, but it will not resolve your problem with page refresh.

0

My first bunch of code works where I have set the value to @Request.Form["selDay"]. It wasn't working because I had set the default value to this input type date on my $(document).ready() function of jquery! Stupid me!

Bivo Kasaju
  • 1,143
  • 3
  • 13
  • 28