[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 673
  • Last Modified:

ASP.Net MVC 4 C# -- textbox blank after click

How can I get the below "Desired Steps" working in ASP.Net MVC 4 C# ?
---------------------------------------------------------
Current Steps
 1. edit POdetailController.cs
      ** change below Edit method
           podetail.ApprovedDate = DateTime.Now;
           return View(podetail);
 2. user logs into APP, clicks Edit
 3. APPROVED textbox automatically displays today's date
 4. user manually removes date if they do NOT approve
---------------------------------------------------------
Desired Steps
 1. user logs into APP, clicks Edit
 2. APPROVED textbox automatically displays BLANK
 3. user clicks inside APPROVED textbox
 4. today's date appears
 5. user clicks inside APPROVED textbox again
 6. today's date gets removed
0
finance_teacher
Asked:
finance_teacher
  • 2
1 Solution
 
Craig WagnerSoftware ArchitectCommented:
Seems like it would make the most sense to handle this client-side.

<input id="approved" type="text" onclick="toggle()" />

<script>
    function toggle() {
        var box = document.getElementById("approved");

        if (box.value === "") {
            box.value = new Date();
        }
        else {
            box.value = "";
        }
    }
</script>

Open in new window

0
 
finance_teacherAuthor Commented:
Below works, but allows users to enter their own text next to the automatic date text.

This is a box they click into when they are done approving an item, I don't want to allow users to type additional text.

How can I setup so users CANNOT enter their own text, they can only save the SYSTEM generated TEXT that happens after they click ?

Other option would be to change from a textbox to an "Approved" checkbox and then write logged in user/today'sDate to database.
------------------------------------------------------------------------------------------------------------
            @Html.TextBoxFor(model => model.LastModifiedBy, new { @onclick = "toggle()" })
------------------------------------
    <script>
        function toggle() {
            var box = document.getElementById("LastModifiedBy");

            if (box.value === "") {
                box.value = new Date();
            }
            else {
                box.value = "";
            }
        }
</script>
0
 
Craig WagnerSoftware ArchitectCommented:
Have you tried disabling the textbox? I'm not sure if that would kill the response to the click event but it's worth a try.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now