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

Posted on 2013-06-11
Last Modified: 2013-07-11
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
Question by:finance_teacher
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 21

Accepted Solution

Craig Wagner earned 500 total points
ID: 39246266
Seems like it would make the most sense to handle this client-side.

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

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

        if (box.value === "") {
            box.value = new Date();
        else {
            box.value = "";

Open in new window


Author Comment

ID: 39276009
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()" })
        function toggle() {
            var box = document.getElementById("LastModifiedBy");

            if (box.value === "") {
                box.value = new Date();
            else {
                box.value = "";
LVL 21

Expert Comment

by:Craig Wagner
ID: 39276139
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.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL ( and MongoDB (…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor ( Top Charts is a view in which you can set seve…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question