Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8539483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:22:34+00:00 2026-06-11T11:22:34+00:00

Javascript newbie question I’m fetching user input from text and use that value to

  • 0

Javascript newbie question
I’m fetching user input from text and use that value to send to the controller for further process. On page init everything is fine, now I want to bind OK button to send users value to my page init script (I’m trying to avoid copying script). Here’s the code

@Html.ActionLink("OK", "Ajax", null, new { @class = "button", @id ="myDate" }) 

on page init

$(document).ready(function dataTable() {
  $('#dataTable').dataTable({
            "bServerSide": true,
             "fnServerParams": function (aoData) {
                var date = $('input[name="myDate"]').val();
                aoData.push({ "name": "Date", "value": date });
   });
});

on user input and clicking the button I should take that input and sent to the above script to process

 $('#myDate').click(function () { 
     var date = $('input[name="myDate"]').val();
     // ????
     // Should I change first function to receive parameter as argument 

});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:22:35+00:00Added an answer on June 11, 2026 at 11:22 am

    One way is to factor out the code to get the date outside the datatable init

    function getDate(){
        var date = $('input[name="myDate"]').val();
        return date;
    }
    

    Then in your datatable init

     var date = getDate();
    

    and the same in your click event

     $('#myDate').click(function () { 
         var date = getDate();
      });
    

    You should end up with this

        $(document).ready(function dataTable() {
            function getDate(){
            var date = $('input[name="myDate"]').val();
           return date;
          }
    
         $('#dataTable').dataTable({
            "bServerSide": true,
             "fnServerParams": function (aoData) {
                var date = getDate();
                aoData.push({ "name": "Date", "value": date });
                   });
               });
    
    
                  $('#myDate').click(function () { 
                     var date = getDate();
                  });
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a newbie question: Can the following HTML/JavaScript code be further simplified by
A newbie question from me, please. I have a large data set that I
Bit of a javascript newbie so not sure if this question is easy or
I am a newbie at Javascript and Jquery. I have a form that I
I am newbie. many of javascript code start with <!-- <script type=text/javascript> <!-- and
this must be a newbie question. I have this method in a controller: public
Newbie ajax question from this example : How is xmlhttp.responseText assigned before xmlhttp.open() and
Newbie question. Why is this JavaScript function returning undefined? var redis = require(redis), client
Rails newbie question that I can't seem to figure out. At some point I
This is a newbie question: I have a pre-existing function that I would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.