The date entered in the input field should also appear in all other textboxes on the

I currently have 2 tables set up on my page. In the first table, there is a textbox (txt1) that includes a date picker. The second table contains 5 similar textboxes (txt2, txt3, txt4, txt5, txt6) also with date pickers.

My requirement is as follows:

Initially, all the text boxes should display today's date. When I change the date in the textbox in the first table, all the textboxes in the second table should automatically update to reflect the date chosen in the first table. I am looking for either a VB code or a JavaScript solution to achieve this functionality.

I have already implemented code to display today's date, but I'm struggling to code for the scenario described above.

If txt1.Text = "" Then
    txt1.Text = Format((Date.Today), "dd-MMM-yyyy")
    If txt1.Text <> "" Then
        txt2.Text = txt1.Text
        txt3.Text = txt1.Text
        txt4.Text = txt1.Text
        txt5.Text = txt1.Text
        txt6.Text = txt1.Text
    End If
End If

Answer №1

Upon page load, include the following code:

protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            txt1.Text = DateTime.Now.ToString();
        }
    } 

This will set the text of textbox 1 to today's date on the initial page load.


protected void txt1_TextChanged(object sender, EventArgs e)
    {   
              If txt1.Text = "" Then

                    If txt1.Text <> "" Then
                        txt2.Text = txt1.Text
                        txt3.Text = txt1.Text
                        txt4.Text = txt1.Text
                        txt5.Text = txt1.Text
                        txt6.Text = txt1.Text
                    End If
                End If

 }

You can add your specific conditions within the txt1_TextChanged event for textbox1. When the text in textbox1 changes, this event will trigger and populate all textboxes with the date accordingly.

<asp:TextBox ID="txt1" AutoPostBack="true" runat="server" Width="83px" ontextchanged="txt1_TextChanged" ></asp:TextBox>  

Answer №2

 public void LoadPage(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Textbox1.Text = DateTime.Now.ToString();
            OnTextChanged(Textbox1.Text);
        }
        else
        {
            OnTextChanged(Textbox1.Text);
        }
    }

    public void OnTextChanged(object sender, EventArgs e)
    {
        Textbox2.Text = Textbox1.Text;
    }

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>New Page</title>
</head>
<body>

    <form id="form1" runat="server">
    <div>
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnableScriptGlobalization="true"
        EnablePartialRendering="true">
    </asp:ScriptManager>
        <asp:TextBox ID="Textbox1" AutoPostBack="true" runat="server" 
            ontextchanged="OnTextChanged"></asp:TextBox>
        <cc1:MaskedEditExtender ID="MaskedEditExtender1" runat="server" TargetControlID="Textbox1"
            Mask="99/99/9999" MaskType="Date" />
        <cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="Textbox1"
            Format="dd/MM/yyyy">
        </cc1:CalendarExtender>
        <asp:TextBox ID="Textbox2" runat="server"></asp:TextBox>
        <cc1:MaskedEditExtender ID="MaskedEditExtender2" runat="server" TargetControlID="Textbox2"
            Mask="99/99/9999" MaskType="Date" />
        <cc1:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="Textbox2"
            Format="dd/MM/yyyy">
        </cc1:CalendarExtender>
    </div>
    </form>
</body>
</html>

This code can be added and it will function correctly.

Answer №3

I've implemented the solution you need using jQuery. Here's how you can do it:

Simply add the following code snippet within the head element of your HTML document:

<head runat="server">

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>


     <script>
         $(function () {
             $("#txt1").datepicker();
             $("#txt2").datepicker();
             $("#txt3").datepicker();
             $("#txt4").datepicker();
             $("#txt5").datepicker();
             $("#txt6").datepicker();
         });
         $(document).ready(function () {
             ShowTime();
             $("#txt1").change(function () {
                 $("#txt2").val($("#txt1").val());
                 $("#txt3").val($("#txt1").val());
                 $("#txt4").val($("#txt1").val());
                 $("#txt5").val($("#txt1").val());
                 $("#txt6").val($("#txt1").val());
             });
         });
         function ShowTime() {
             var dt = new Date();
             $("#txt1").val($.datepicker.formatDate('mm/dd/yy', new Date()));
             $("#txt2").val($.datepicker.formatDate('mm/dd/yy', new Date()));
             $("#txt3").val($.datepicker.formatDate('mm/dd/yy', new Date()));
             $("#txt4").val($.datepicker.formatDate('mm/dd/yy', new Date()));
             $("#txt5").val($.datepicker.formatDate('mm/dd/yy', new Date()));
             $("#txt6").val($.datepicker.formatDate('mm/dd/yy', new Date()));

         }

</script>
</head>

Note: I have set the date format to 'mm/dd/yy', feel free to adjust the code if you require a different format.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Learn the steps to successfully select a drop-down option by clicking on a button

Below is the HTML code for my select options: <select id="font"> <option value="School">School</option> <option value="'Ubuntu Mono'">SansitaOne</option> <option value="Tangerine">Tange ...

Steps to Activate a Hyperlink for Opening a Modal Dialogue Box and Allowing it to Open in a New Tab Simultaneously

I am currently working on a website project. Within the website, there is a hyperlink labeled "View Page". The intention is for this link to open the linked page in a modal dialog upon being clicked. Below is the code snippet that I have used to achieve t ...

populating a multi-dimensional array using a "for" loop in Javascript

It appears that JavaScript is attempting to optimize code, causing unexpected behavior when filling a multidimensional array (largeArr) with changing values from a one-dimensional array (smallArr) within a loop. Take the following code for example: largeA ...

Strategies for retaining additional fields added via JavaScript when the page is refreshed

var newField = document.createElement("lastExp"); newField.innerHTML = 'insert new form field HTML code here'; document.getElementById("lastExp").appendChild(newField); I have a button that adds an additional form field with a simple click. ...

Learn the trick to make this floating icon descend gracefully and stick around!

I'm trying to create a scrolling effect for icons on my website where they stay fixed after scrolling down a certain number of pixels. I've managed to make the header fixed after scrolling, but I'm unsure how to achieve this specific effect. ...

Experiencing difficulties with a click event function for displaying or hiding content

Struggling with implementing an onClick function for my two dynamically created components. Currently, when I click on any index in the first component, all content is displayed. What I want is to show only the corresponding index in the second component ...

Retrieving data from a dynamic array using jQuery

Within my code, I am working with an array that contains IDs of div elements (specifically, the IDs of all child div elements within a parent div with the ID of #area): jQuery.fn.getIdArray = function () { var ret = []; $('[id]', this).each(fu ...

I am encountering difficulties with a nodejs query where I am unable to successfully include the "+" symbol as part of the query

Every time I submit a query for B+ or A+ {{URL}}/api/help/?bloodType=B+ it ends up showing as empty space, like this. Is there a way to properly pass the "+" sign in the query? Thanks. P.S: _ works fine. {"bloodType":"B "} ...

Utilizing columns within the 'segment' element in Semantic-ui to enhance layout design

I am looking to divide the ui-segment into 3 columns and display the ui-statistics evenly. Below is the code I have used in an attempt to achieve this: <div class="ui container"> <div class="ui segment"> <h3 class="ui header"> ...

Rotating the camera around the origin in Three.js

Hey, I'm having some trouble with what I thought would be a simple task. I have a group of objects at the origin, and I'm trying to rotate a camera around them while always facing the origin. According to the documentation, this code should work: ...

Tips for incorporating a JavaScript file directly into your HTML code

I'm working with a compact javascript file named alg-wSelect.js, containing just one line of code: jQuery('select.alg-wselect').wSelect(); This script is used by a wordpress plugin. My question is whether it's feasible to incorporate th ...

Avoid activating the panel by pressing the button on the expansion header

I'm facing a problem with the delete button on my expansion panel. Instead of just triggering a dialogue, clicking on the delete button also expands the panel. How can I prevent this from happening? https://i.stack.imgur.com/cc4G0.gif <v-expansion ...

The v-menu closes before the v-list-item onclick event is detected

I have set up the following menu using vue and vuetify: <div id="app"> <v-app id="inspire"> <div class="text-center"> <v-menu> <template v-slot:activator="{ on }"> ...

Redirecting to another page with a simple link is not recommended

Once the user successfully logs in, I redirect them to the dashboard. Everything was working fine until I deployed it using tomcat. Now the URL is http://localhost:8080/myWar/ So when I use this: window.location.href = "/dashboard"; it redirects to ht ...

Issue encountered when employing the spread operator on objects containing optional properties

To transform initial data into functional data, each with its own type, I need to address the optional names in the initial data. When converting to working data, I assign a default value of '__unknown__' for empty names. Check out this code sni ...

What is the method for retrieving the active element with Waypoint?

Currently, I am implementing Waypoint (version 7.3.2) in my React project using React version 16. My goal is to create a scrollable list of items where each item fades out as it reaches the top of the container div. My main inquiry is how can I obtain a re ...

Can fetch be used to retrieve multiple sets of data at once?

Can fetch retrieve multiple data at once? In this scenario, I am fetching the value of 'inputDest' (email) and 'a' (name). My objective is to obtain both values and send them via email. const inputDest = document.querySelector('i ...

I encountered an error while trying to deploy my next.js project on Vercel - it seems that the module 'react-icons/Fa' cannot be found, along with

I'm currently in the process of deploying my Next.js TypeScript project on Vercel, but I've encountered an error. Can someone please help me with fixing this bug? Should I try running "npm run build" and then push the changes to GitHub again? Tha ...

Alter the button's color seamlessly while staying on the same page

I have implemented a feature that allows me to change the category of photos without having to leave the page and it works perfectly. My next goal is to create a button system where the pre-defined category of a photo is indicated by a button with a green ...

Transmit a data element from the user interface to the server side without relying on the

I have developed a MEAN stack application. The backend of the application includes a file named api.js: var express = require('express') var router = express.Router(); var body = 'response.send("hello fixed")'; var F = new Function (" ...