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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity figure out error 3 26
How to escape alias names for Oracle query 1 25
Need help with a query 14 39
Validation for a field in 3 15
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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question ( here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 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