0

I have textbox with generated html

<input id="datePicker" class="date hasDatepicker" type="text" value="" name="date">

$(document).ready(function () {
        var data = $("#datePicker").val();

        $(".dateBtn").click(function (event) {
            FetchDetails(data);
        })
....

Onclick textbox is populated at the page but no value is being sent to the FetchDetails function. What I am doing wrong here?

Thanks

1
  • you kept value attribute null? Commented Jun 7, 2013 at 8:56

2 Answers 2

4

It is because you are reading the value of the input field at the page load and assigning the value to data. Any changes made the in input value will not be reflected in the variable data.

The solution is to read the input's value when you need it, so that you can get the up to date value

You need to

$(".dateBtn").click(function (event) {
            FetchDetails($("#datePicker").val());
        })
Sign up to request clarification or add additional context in comments.

Comments

1

Try like

$(document).ready(function () {        
    $(".dateBtn").click(function(event) {
        var data = $("#datePicker").val();
        FetchDetails(data);
    });
});

It is better to get the text box value after clicked on the button,Because in your case data will get on the document ready and if we changed further that value then it should be remain same

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.