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 6946685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:35:48+00:00 2026-05-27T13:35:48+00:00

I am somewhat a beginner to jquery. I am having trouble creating a function

  • 0

I am somewhat a beginner to jquery. I am having trouble creating a function to fill a textbox with the current date when a checkbox is clicked. I have the routine working on its own, but i would like to wrap it in a function so i can call it multiple times on the page. I have included the code here as well as a jsfiddle link

jsFiddle Link

html:

 <span id="ContentPlaceHolder1_Label8">Start Date:</span>

        <input name="ctl00$ContentPlaceHolder1$startdateSrvcTXT" type="text" id="ContentPlaceHolder1_startdateSrvcTXT" disabled="disabled" class="aspNetDisabled" />

        <span id="ContentPlaceHolder1_Label11">Check to Start</span>

        <input id="ContentPlaceHolder1_StartFillCHK" type="checkbox" name="ctl00$ContentPlaceHolder1$StartFillCHK" />

javascript:

/*----This works------
$('#ContentPlaceHolder1_StartFillCHK').click(function () {

                if (this.checked) {

                    var myDate = new Date();

                    var prettyDate = (myDate.getMonth() + 1) + '.' + myDate.getDate() + '.' +

myDate.getFullYear();

                    $('#ContentPlaceHolder1_startdateSrvcTXT').val(prettyDate);

                } else { //if not checked

                    $('#ContentPlaceHolder1_startdateSrvcTXT').val('');

                }

            });

*/

//this doesnt
function fillclick(txtid,checkid){
$("'" + checkid + "'").click(function () {

                if (this.checked) {

                    var myDate = new Date();

                    var prettyDate = (myDate.getMonth() + 1) + '.' + myDate.getDate() + '.' +

myDate.getFullYear();

                    $("'" + txtid + "'").val(prettyDate);

                } else { //if not checked

                    $("'" + txtid + "'").val('');

                }

            });
}

fillclick("#ContentPlaceHolder1_startdateSrvcTXT","#ContentPlaceHolder1_StartFillCHK");
  • 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-05-27T13:35:49+00:00Added an answer on May 27, 2026 at 1:35 pm

    You’re querying by ID; you need to use # selectors:

    $("#" + checkid).click
    

    and

    $("#" + txtid).val
    

    Edit: You’re already using them. There’s no need to quote anything, they’re already strings:

    $(checkid).click
    

    and

    $(txtid).val
    

    .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apologies for the big block 'o' text, but I'm somewhat of a beginner having
Although somewhat related to this question , I have what I think is a
I have somewhat interesting development situation. The client and deployment server are inside a
somewhat simple problem(to explain) this time: i have an array of markers that i
Most somewhat modern programming languages have a standard library? It is my impression is
I somewhat understand descendant selectors, but the more complex examples are giving me trouble.
Somewhat new to jQuery, so excuse the attempt at properly identifying things. I need
I'm new to multithreading (and a somewhat beginner / intermediate programmer), and so I
I'm somewhat of a Rails beginner, and can't shake the feeling that I'm overlooking
I'm fairly new to C++ so this is probably somewhat of a beginner question.

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.