Is there a way to retrieve the content from an asp.net mvc textbox using javascript?

Is there a way to access the content of an ASP.NET MVC textbox using JavaScript?

I have two textboxes displayed below and I am attempting to extract the data entered via a date-picker using the following JavaScript code. However, my current approach is returning null values.

Code:

@Html.Label("Start", "Start Date:")
@Html.TextBox("Start", string.Empty, new {@id = "Start", @class = "datepicker"})
@Html.Label("endd", "End Date:")
@Html.TextBox("endd", string.Empty, new {@id = "End", @class = "datepicker"})
<input type="submit" value="Apply" id ="DateSelected" />


<script type="text/javascript">
  $('.datepicker').datepicker();
$("#DateSelected").onclick(function () {
            var value1 = document.getElementById('<%=Start.ClientID%>').value;
            var value2 = document.getElementById('<%=End.ClientID%>').value;

</script>

Answer №1

To modify your Javascript, you could consider the following changes:

<script type="text/javascript>
    $('.datepicker').datepicker();
    $("#DateSelected").click(function () {
            var value1 = document.getElementById('Start').value;
            var value2 = document.getElementById('End').value;

</script>

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

Looping Feature in Ionic Framework's Slides Component

Currently, I am working on developing an application using Ionic-Angular. When it comes to incorporating slides in my app, I opted for the ionic 4 ion-slides component. Everything was going smoothly until I wanted to enable looping for the slides so that u ...

The menu field remains open even after clicking on the menu

I have encountered an issue with my code. Here is a DEMO that I created on jsfiddle.net Currently, when you click on the red div, the menu opens. However, if you click on the menu items, the menu area does not close. What do I need to do in order to clo ...

Display items in Angular-js based on their children property

Is it possible to dynamically set the ng-show property of #category based on the value of item.show? I want #category to be visible only if at least one of the items in that category is shown. How can this be achieved using AngularJS? I'm still learni ...

Vue encountered an unexpected issue: fn.bind is not recognized as a function

My Vue application structure is as follows: <template> <div id="app"> <home-central></home-central> </div> </template> <script> import HomeCentral from './components/HomeCentral'; export defau ...

Unable to dynamically add image to React component

I'm facing an issue while trying to pass the image source as a prop in my code. The error message I receive is: Uncaught Error: Cannot find module '../4.0 - Assets/Images/video-list-1.jpg' Can anyone help me resolve this? Below is the code ...

Initiate a Gravity Forms form refresh after modifying a hidden field with jQuery

TO SUM IT UP: Is there a way in Javascript to activate an update on a Gravity Form that triggers the execution of conditional logic? ORIGINAL QUESTION: I'm using Gravity Forms and I have set up an "on change" event $('#gform_1').find(&apos ...

The robots.txt file in Nuxt.js allows for multiple disallow directives for each user agent

With the Nuxt module called nuxt-robots, how can I set up multiple disallow rules per user agent? Currently, my configuration looks like this: robots: () => { return { UserAgent: '*', Disallow: '/search/', Si ...

Transferring a variable from a scriplet to JSP with the issue of a null

Seeking assistance with passing a variable from a scriptlet in one jsp to the 'calling jsp' The scenario involves assetedit.jsp posting a binary stream to upload.jsp. However, despite the processing of the stream in upload.jsp and determination ...

Is AngularJS the right choice for developing this application?

Recently, I've come to the realization that I want to dive into the world of AngularJS framework after working with jQuery for several years. I have a vision of developing an application that allows users to easily modify webpage DOM using a browser- ...

Firebase is unable to generate a new document

Recently, my firebase project has been experiencing an issue where it is unable to create new documents after the last build. While it can save and update existing documents, the function for creating new ones seems to be failing. The function responsible ...

I encounter an error while attempting to deserialize a JSON string, making it impossible to

I am encountering an issue with the following code snippet: string downloadString = client.DownloadString(serviceurl); List<Player> myDeserializedObjList = (List<Player>)JsonConvert.DeserializeObject(downloadString, typeof(List<Player>)) ...

`Using Rollup to combine local typescript files into a single main bundle`

I'm currently working on developing an npm module that is intended for use in web browsers. For this project, I have chosen to utilize TypeScript and Rollup as my tools of choice. Here is a snippet of my tsconfig.json: { "compilerOptions": { " ...

How can you efficiently cache a component fetching data from an API periodically in React?

I have a situation where I need to continuously fetch data from an API at intervals because of API limitations. However, I only want to update the state of my component if the API response is different from the previous one. This component serves as the m ...

Angular: Arrange items by a combination of ascending and descending properties

When iterating through my ng-repeat, I need a specific order for my items. I know I can use a list of properties to set the order: ng-repeat="client in clients | orderBy: ['isOpen', 'lastAccessTime']" My question is, how can I specify ...

Tips for effectively utilizing Enums with switch statements in typescript

In one file, I have the following code snippet: export module Utils { export enum DataSources { SharepointList = "SharepointList", JsonData = "JsonData" }; } And in another file, there is the following code: import CustomerDAO f ...

Is there a way to retrieve information specifically from a choice column in a SharePoint list rather than the entire data set in SharePoint using Asp.Net?

In my Sharepoint List named 'Notifications', there are columns for 'ID', 'Name', and 'Areas' (a MultiChoice column). Is it possible to retrieve the choices from the 'Areas' column itself, rather than from t ...

Unexpected halt in C# thread functionality occurs

In my multi-threaded application (TCPListener), one thread is responsible for checking a list of requests and sending data if a request is available. The code snippet below demonstrates this process: private void HandleClientRequestsTask() { try { ...

Failure of MySQL Transactions to Rollback

Currently, I am working on an import routine that should fail entirely if any errors occur during the process. The setup involves utilizing a MySQL database with InnoDB and an ASP page to handle the importing task. My intention is to initiate a transaction ...

Use javascript to implement lazy-loading for images

Looking to enhance website performance by lazy loading images. Plan is to initially display a set number of images and then load the rest lazily. Here's what I have currently: Check out the code here <div> <img src="http://i.imgur.com/CmU ...

Sending the format of the display value to an Angular component

Looking for a way to pass display value formatting to an Angular component. Here are a couple of examples: format="'(utc, offset) location (tz)'" === '(UTC -04:00) New York (EDT)' or format="'(tz, offset) location'" === &a ...